I’ve been working on a commission recently and I ran into a problem:
- My checkpoint script won’t move the player to the first checkpoint.
- What am I missing? A simple wait or a
repeat wait()
?
local checkpoints = game.Workspace:WaitForChild("Checkpoints")
local DS = game:GetService("DataStoreService")
local Key = DS:GetDataStore("Stages")
game.Players.PlayerAdded:Connect(function(player)
local data = Key:GetAsync(player.UserId .. "-CurrentStage")
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local Stage = Instance.new("IntValue")
Stage.Name = "Stage"
Stage.Parent = folder
Stage.Value = data or 0
local value2 = Instance.new("BoolValue") -- for timing the player, ignore this for now.
value2.Name = "Started"
value2.Value = false
value2.Parent = player
player.CharacterAdded:Connect(function(char)
wait()
local hum = char:WaitForChild("Humanoid")
char:MoveTo(checkpoints[Stage.Value].Position)
player.Started.Value = false
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
hit.TouchEnded:Connect(function(hit)
player.Started.Value = true
end)
if tonumber(hit.Name) == Stage.Value + 1 then
Stage.Value = Stage.Value + 1
player.Started.Value = false
end
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
Key:SetAsync(player.UserId .. "-CurrentStage", player.leaderstats.Stage.Value)
end)