sometimes when the player spawns they spawn at the spawn location instead of the checkpoint, i tried deleting the spawn location but it still does that
script:
local checkpoints = workspace:WaitForChild(“Checkpoints”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0
stage.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[stage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == stage.Value + 1 then
stage.Value = stage.Value + 1
end
end
end)
end)
Just change the CFrame or Position of the Character.HumanoidRootPart, using the :MoveTo() function is used for making the character walk to a given position.
player.CharacterAdded:Connect(function(char)
repeat task.wait(0.1) until char:FindFirstChild("HumanoidRootPart") and char:FindFirstChildWhichIsA("Humanoid")
local hum = char:FindFirstChildWhichIsA("Humanoid")
char:SetPrimaryPartCFrame(checkpoints[stage.Value].CFrame)
-- do touching stuff here (YOU CANT DETECT .TOUCHED FOR HUMANOIDS)
end)
Maybe try your code like this so there is no delay in setting up the playeradded function (there is a chance that it won’t catch the first player joining the came you can detect this with adding prints to test your code)
game.Players.PlayerAdded:Connect(function(player)
print('PlayerJoined ', player) -- for testing
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 0
stage.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local checkpoints = workspace:WaitForChild(“Checkpoints”) -- moved this here so it won't delay the player added function
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[stage.Value].Position)
print('CharacterMoved ', char) -- for testing
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == stage.Value + 1 then
stage.Value = stage.Value + 1
end
end
end)
end)
end)