Doing Humanoid.Died when a player is leaving

I have some scripts that depend on Humanoid.Died to run and when the player leaves, they do not run which creates a problem, What is the best fix to this issue? I tried using game.Players.PlayerRemoving but it seems to only work in ServerScriptService while the script I’m using isn’t in it

1 Like

Just make a function for that, and just use it when the player leaves or dies

Is this only happening in Studio? Because sometimes PlayerRemoving does not fire in Studio, but it works in game.

And!!! Use it for game:BindToClose() too

I don’t need that if the server is closing then there is no point it’s nothing related to player data

Should PlayerRemoved work outside ServerScriptService?

But for the bind to close use it like this, for i, p in pairs(game.Players:GetPlayers()) do
—do stuff
end

No, it works everywhere just in a script

PlayerRemoving should work everywhere.

Okay thank you I’ll try it in a server

It didn’t work even in a roblox server