Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I turn a wait() into a WaitForChild/PlayerAdded?

Asked by 6 years ago

I am making a script where character will spawn in at spawn #1 but when the character dies he will spawn at spawn #2 somewhere else, the script works perfectly in studio but does not on Roblox itself, so I resolved that instead of using a regular wait() I should wait until PlayerAdded, but I have no clue how to do this sort of thing because it uses functions. Script:

workspace.Model.SpawnLocation.Enabled = true --Spawn #1
workspace.Cell.SpawnLocation.Enabled = false --Spawn #2
wait(1)
workspace.Model.SpawnLocation.Enabled = false
workspace.Cell.SpawnLocation.Enabled = true

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Something like this?

local Spawn1 = workspace:WaitForChild('Model'):WaitForChild('SpawnLocation')
local Spawn2 = workspace:WaitForChild('Cell'):WaitForChild('SpawnLocation')

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local HRP = char:WaitForChild('HumanoidRootPart')
        local Humanoid = char:WaitForChild('Humanoid')

        HRP.CFrame = Spawn1.CFrame

        Humanoid.DIed:connect(function()
            wait(1)
            local char = plr.Character or plr.CharacterAdded:wait()

            local HRP = char:WaitForChild('HumanoidRootPart')
            HRP.CFrame = Spawn2.CFrame
        end
end)

I didn't use Enabled because if it's multiplayer it would change the spawn for anyone

0
I would replace line 11 with "char.Humanoid.Died:Connect(function()" then put lines 12-16 inside of the function. justoboy13 153 — 6y
0
it tells me "bad argument" at line 9 lolkid007 43 — 6y
0
Sorry, use Spawn1.CFrame, same with Spawn2 User#20388 0 — 6y
0
says same thing, bad argument #3 to 'CFrame' (CFrame expected, got Object) lolkid007 43 — 6y
View all comments (6 more)
0
I'll update the script User#20388 0 — 6y
0
Should work now User#20388 0 — 6y
0
doesn't work :P lolkid007 43 — 6y
0
thanks for trying to help though lolkid007 43 — 6y
0
Do you have any errors? User#20388 0 — 6y
0
Try now, I updated the script again User#20388 0 — 6y
Ad

Answer this question