That can be because your body parts are touching the checkpoint, your script does not include any checking if the touched player is dead or not. Logically the player is dead if humanoid's health is lower than 0, you can use the method below.
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid and Humanoid.Health > 0 then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Stage = Player:WaitForChild("leaderstats"):WaitForChild("Stage")
if Stage.Value == script.Parent.Name - 1 then
Stage.Value = script.Parent.Name
end
end
end
end)
- Don't use
:connect with lowercase "c", it's deprecated
- I recommend you using FindFirstChildOfClass which will only look for humanoids no matter what their name is, previously you could trick this by making a random part called "Humanoid" inside the character
- Instead of looking for name of the character in
Players, use GetPlayerFromCharacter function which is made exactly for that
- Prefer using GetService instead of indexing them as
game.Service, if you rename the service you want to get, the second method won't work. This happens very rarely, it's still a good practice though
Also notice how you put the same script into all checkpoints, if you want to make a little change you must modify each of them, you can avoid that by putting checkpoints into their specific folder and creating a script which will apply same functions to them, this is done using ipairs, here is an example of how you can make it work:
ServerScriptService.CheckpointSystem
local Checkpoints = game.Workspace.Checkpoints
for _, Checkpoint in ipairs(Checkpoints:GetChildren()) do
Checkpoint.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid and Humanoid.Health > 0 then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local Stage = Player:WaitForChild("leaderstats"):WaitForChild("Stage")
if Stage.Value == script.Parent.Name - 1 then
Stage.Value = script.Parent.Name
end
end
end
end)
end
2 comments
how are you able to repost answers several times?
holy no i can explain - i was in prague and scriptinghelpers is broken there so i was getting 504 & 502 errors when i tried to post my answer, at the end i gave up but all my attempts were actually posted lol