How do I make it so that I don't need the task.wait(1)

local Spawn1 = game.Workspace:WaitForChild("Spawn1")
local Spawn2 = game.Workspace:WaitForChild("Spawn2")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		
		task.wait(1)
		
		if player:FindFirstChild("Stage") then
			
			local Stage = player.Stage.Value
			
			if Stage == 1 then
				player.Character:FindFirstChild("HumanoidRootPart").CFrame = Spawn1.CFrame + Vector3.new(0,2,0)
			elseif Stage == 2 then
				player.Character:FindFirstChild("HumanoidRootPart").CFrame = Spawn2.CFrame + Vector3.new(0,2,0)
			end
		end
	end)
end)

Hello, everything in this script works fine but I don’t want to use task.wait anymore because the time it takes to tp the player can vary and I don’t want that. The stage is a datastore value so it doesn’t load in instantly. How can I make it keep checking for the stage until 1 or 2?

You can use WaitForChild to wait for the humanoid to load in.

player.Character:WaitForChild("Humanoid")
--!nonstrict
local Stage = nil
repeat
   wait()
   Stage = player:FindFirstChild("Stage")
until Stage

or

--!strict
local Stage: number? = nil
repeat
   wait()
   Stage = player:FindFirstChild("Stage").Value
until typeof(Stage) == "number"

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.