Hey everyone, I’m currently having issues with my checkpoint script. The script takes a value from the player and uses that to decide where they spawn. Currently the script is working fully but occassionally the player spawns the player off in the void and they fall to their death. This happens about a 5th of the time and I’m stumped as to why. Attached is a video of the player respawning normally a few times then spawning somewhere random and dying.
robloxapp-20230524-0115388.wmv (2.8 MB)
The script in question
function plrToStage(plr)
repeat wait() until plr.Character.HumanoidRootPart
local stagePart = game.Workspace.Checkpoints:FindFirstChild(tostring(plr.Values.Stage.Value))
plr.Character.HumanoidRootPart.CFrame = stagePart.CFrame + Vector3.new(0,2.5,0)
end
game.Players.PlayerAdded:Connect(function(player)
if player.Character then
plrToStage(player)
end
player.CharacterAdded:Connect(function()
plrToStage(player)
end)
end)
for _, cheackpoint in pairs(game.Workspace.Checkpoints:GetChildren()) do
cheackpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local cheackpointNumber = tonumber(cheackpoint.Name)
player.Values.Stage.Value = cheackpointNumber
end
end)
end
Originally this script was apart of my leaderboard that tracks and assigns stats to the player but I moved it to a seperate script to see if the leaderboard script was causing the checkpoint portion of the script to lag behind. This didn’t fix the issue and now I’m stumped and could use a hand.