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
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