checkPoints = game.Workspace:WaitForChild("Checkpoints")
local timer = false
game:WaitForChild("Players")
script.Parent.Touched:Connect(function(hit)
if timer == false then
timer = true
if (hit.Parent:FindFirstChild("Humanoid")) then
local Player = game.Players[hit.Parent.Name]
if (Player.leaderstats.Lives.Value > 0) then
Player.leaderstats.Lives.Value = Player.leaderstats.Lives.Value - 1
end
if (Player.leaderstats.Lives.Value <= 0) then
Player.leaderstats.Lives.Value = 3
Player.leaderstats.World.Value = 1
Player.leaderstats.Stage.Value = 1
Player:LoadCharacter()
else
local pSpawn = checkPoints:WaitForChild(tostring(Player.leaderstats.World.Value)):WaitForChild(tostring(Player.leaderstats.Stage.Value)) -- Respawns player
hit.Parent.HumanoidRootPart.CFrame = pSpawn.CFrame
end
end
wait(0.5)
timer = false
end
end)
This is my code. I even added a "game:WaitForChild("Players")" at the beginning but that didn't work. Also I should mention i'm new to Lua

3 comments
What line is breaking your script?
Oh sorry its line 9
I should also mention this script works on some objects but not one in particular?