I have made the checkpoint system but when i test it and I die, my body parts have a chance to touch the next checkpoint, if it does then I get that checkpoint and pretty much skip the previous stage.
How do I make it so when the player dies and it’s body parts touches the next checkpoint it doesn’t count it as the player has reached the next stage and the player will be respawned back the to the stage it had died on?
Check if the player is dead before changing their checkpoint
example.Touched:Connect(function(hit) -- hit is a body part
local humanoid = hit.Parent:FindFirstChild("Humanoid") -- the humanoid has information about the players health
if not humanoid then return end -- stop checking if there is no humanoid
if humanoid.Health <= 0 then return end -- stop if the player is dead (0 health)
--anything past this point will only run for alive players
--change checkpoint here
end)
I’m not sure but I think your code doesn’t work because you didn’t put an if-statement to check that the thing that touches the value/checkpoint is Humanoid or not. Which matters because your code doesn’t know what actually touches or needs to touch the part.
I didn’t test to see if its true, its a minor change but it deserves trying.
for i, v in pairs(checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player or not player:FindFirstChild("leaderstats") then
return
v.Touched:Connect(function(hit) -- hit is a body part
local humanoid = hit.Parent:FindFirstChild("Humanoid") -- the humanoid has information about the players health
if not humanoid then return end -- stop checking if there is no humanoid
if humanoid.Health <= 0 then return end -- stop if the player is dead (0 health)
--anything past this point will only run for alive players
--change checkpoint here
end)
How and where do I put it in. I’m not good at scripting but I have no robux to hire one for my game. That’s why I ask. I try to get better though so sorry if my questions sounds bad.