Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Died function not working on reset, but does when killed manually?

Asked by 6 years ago

Hi guys.

So I'm having this terribly annoying issue and I can't find a fix.

When a player dies, I want the script to print a simple string "Died!". However, when the player dies the script just seems to not care and looks the other way. No prints, no errors, nothing!

The funny thing however; when I manually set my Health to 0 in the Humanoid (Workspace > PlayerName > Humanoid), the function DOES fire.

I'm using a server-sided script in ServerScriptService, with the following code; (Has been shortened for simple reading, I made sure no parts are missing.


function died() print("Died!") end game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() died() end) end) end)

Any ideas??

0
`Humanoid.HealthChanged:Connect(function(Health) if Health == 0 then --code end end)`? Might not be the best way, but have you tried that? TheeDeathCaster 2368 — 6y
0
It works on reset, but executes around 5 times during the death-phase. Any ideas? User#20989 0 — 6y
0
Have you tried using `player.Character...` to see what occurs? TheeDeathCaster 2368 — 6y
0
Yep. That's when the script executed 5 times. Normally I would ignore it, but sadly the script is ment to drop certain items upon death later on, which this issue would ruin. User#20989 0 — 6y
View all comments (2 more)
0
When does this not work exactly? I'm using your exact script in studio and it works fine. If I set my health to 0, remove my head or reset, "Died!" prints just fine. optiplex123 21 — 6y
0
When using my script above the Died print doesn't show up. When using the suggested function I have to reset once without seeing the print, but resetting a second time does print the Died! string.. User#20989 0 — 6y

Answer this question