Hello, I have an obby game and I want the player to teleport to the stage they are on when they join. However it is not working and I do not know what is wrong with it. Here is my current code:
game.Players.PlayerAdded:Connect(function(plr)
wait(.1)
local val = plr.leaderstats.Stage.Value
for _,v in pairs(workspace.Checkpoints:GetChildren()) do
if v.Name == val then
plr.Character:FindFirstChild("HumanoidRootPart").CFrame = v.CFrame
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
wait(.1)
local val = plr.leaderstats.Stage.Value
for _,v in pairs(workspace.Checkpoints:GetChildren()) do
if v.Name == val then
plr.Character:PivotTo(v.CFrame)
end
end
end)
game.Players.PlayerAdded:Connect(function(plr)
wait(.1)
local val = plr.leaderstats.Stage.Value
for _,v in pairs(workspace.Checkpoints:GetChildren()) do
if tonumber(v.Name) == val then
plr.Character:PivotTo(v.CFrame)
end
end
end)