I have a problem I have a checkpoint folder in a race and an intvalue that tells me how many checkpoints there are but my code only is teleporting me to the first checkpoint?
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
for Number = 1, workspace.Checkpoints.NumberOfCheckpoints.Value do
pcall(function()
LocalPlayer.Character:MoveTo(workspace.Checkpoints[Number].Position)
end)
wait()
end
BTW am adding another checkpoint for every checkpoint they go thrugh so at the start there is one once they go throigh num 1 I add num 6 num 2 num 7 etc
but it just keeps teleporting them to the first checkpoint idk why
would you want to have you checkpoints as part inside the same parent and do :getchildren()? if so you could do
local Players = game:GetService(“Players”)
local LocalPlayer = Players.LocalPlayer
teleportcheckpoint() --the parameter is the one we want to teleport to eg: teleportcheckpoint(1)
function teleportcheckpoint(num) checkpoint = table.find(workspace.Checkpoints:getchildren(), “checkpoint”…num)
LocalPlayer.Character:MoveTo(checkpoint.position)
end)
wait()
end
This is assuming that the checkpoints are parts named checkpoint1, 2, etc and that they have a .position
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
for i,v in pairs(workspace.Checkpoints:GetChildren()) do
if v:IsA("Part") then
Character:MoveTo(v.Position)
wait(1)
end
end
while true do
local Checkpoints = workspace:FindFirstChild("Checkpoints")
if Checkpoints then
for Number = 1, Checkpoints.NumberOfCheckpoints.Value do
pcall(function()
LocalPlayer:MoveTo(Checkpoints[Number].Position)
end)
wait()
end
else
warn("Checkpoints not loaded!")
end
end
is it successfully teleporting you, if it is, it is most likely eating your memory causing a crash, if it isn’t teleporting then that means the wait() you have is being bypassed meaning it is an infinite loop with no restraints
local Checkpoints = workspace:WaitForChild("Checkpoints")
for _, checkpoint in pairs(Checkpoints:GetChildren()) do
LocalPlayer.Character:MoveTo(checkpoint.Position)
end
That should fix the crashing, wait for the checkpoints to exist and that should teleport you to every checkpoint.
for _, checkpoint in pairs(Checkpoints:GetChildren()) do
LocalPlayer.Character:MoveTo(checkpoint.Position)
LocalPlayer.Character.Humanoid.MoveToFinished:Wait() -- Waits until the player finishes moving.
--Script then moves to the next checkpoint after this. This works with a while true loop.
end
An issue with your script was the fact that it didn’t wait for the player to finish moving to the first checkpoint.