How would i stop a script inside a tool stop running when the player dies

so when the player dies the script inside the tool stops running, how would i prevent this

if Humanoid and Humanoid.Health <= 0 then
   return -- ends function
else
   -- Tool Code
end

You would then set the value of playerIsAlive to false in another script whenever the player dies. This way, the script inside the tool will stop running when the player dies.

or

you could use a boolean variable to keep track of the player’s state (alive or dead), and then use that variable to determine if the script inside the tool should continue running or stop

2 Likes

this will still do the exact same thing:

if not PlayerIsAlive then
    return
else

end

Its just adding an extra step

Humanoid.Died:Connect(function()
    PlayerIsAlive = false
end
2 Likes

yea, but i meant with bool value!

Still the same thing:

if not PlayerIsAlive.Value then
    return
else

end
Humanoid.Died:Connect(function()
    PlayerIsAlive.Value = false
end

you do realise, this is the exact opposite of what i want it to do

1 Like

O O F.


Tools can still fire when you are dead, as long as they are activated by the Player (or Tool:Activate()), they will still fire.

basically the thing i am asking is how to make a script keep running even if its destroyed

Ah, I see. Perhaps you could move your script code into a script elsewhere, or you could move the script when the player dies.

In the case of the former, it really depends what your code actuallt does, so it would be nice if you could just tells us what it does. No code, just information.

In the case of the latter, you can set the script’s RunContext to Server and I believe that may be good enough. If not, you could detect player death as others have mentioned and set the script’s parent to workspace or serverscriptservice or similar.

1 Like