Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

10 comments

0

I would replace line 11 with "char.Humanoid.Died:Connect(function()" then put lines 12-16 inside of the function.

0

it tells me "bad argument" at line 9

0

Sorry, use Spawn1.CFrame, same with Spawn2

0

says same thing, bad argument #3 to 'CFrame' (CFrame expected, got Object)

0

I'll update the script

0

Should work now

0

doesn't work :P

0

thanks for trying to help though

0

Do you have any errors?

0

Try now, I updated the script again

This discussion is preserved as it was. New answers, comments, and votes are closed.