forked from Kampfkarren/Roblox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadRequirement.module.lua
More file actions
45 lines (35 loc) · 1.23 KB
/
LoadRequirement.module.lua
File metadata and controls
45 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
--requires PlayerStorage module, and a folder titled LoadRequirements in the PlayerStorage folder
local PlayerStorage = require(game:GetService("ServerScriptService").PlayerStorage)
local requirements = {}
local LoadRequirement = {}
local server = game:GetService("RunService"):IsServer()
function LoadRequirement:AddRequirement(requirementName, requirementCallback)
local model = Instance.new("Model")
model.Name = requirementName
model.Parent = game:GetService("ServerStorage").PlayerStorage.LoadRequirements
table.insert(requirements, {
name = requirementName,
callback = requirementCallback
})
end
game:GetService("Players").PlayerAdded:connect(function(player)
game:GetService("RunService").Stepped:wait()
local LoadRequirements = PlayerStorage(player).LoadRequirements
for _,requirement in pairs(requirements) do
spawn(function()
requirement.callback(player)
LoadRequirements:WaitForChild(requirement.name):Destroy()
if server then --why do i have this i forget
print(requirement.name .. " loaded.")
end
end)
end
--this is weird
while #LoadRequirements:GetChildren() > 0 do
LoadRequirements.ChildRemoved:wait()
end
if player.Parent then
player:LoadCharacter()
end
end)
return LoadRequirement