Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i do a function on humanoid died?

I'm making a remoteevent with this script and idk why it doesn't works, please help me

--This is a Script
local Event = game.ReplicatedStorage:WaitForChild("RedWin")
local Humanoid = script.Parent:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
	print("hi")
	Event:FireServer()
end)

4 comments

0

Try to kill the "npc" with server. not take damage with client. only server.

0

try adding parameters? and change it to FireClient()??? ^_^

0

RemoteEvents can only be fired to the server when it's in a LocalScript.

0

Are you keeping this script in StarterCharacterScripts?

2 answers

✓ Accepted answer

Try something like this, except in a LOCAL script, inside StarterPlayerScripts

local plr = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("RedWin")

if plr.Character.Humanoid.Health == 0 then -- what to do if the health is 0
	print("hi")
	event:FireServer(plr) -- you will want to do this to let the server know which player died.
end

thanks for the help but i need this script for an npc , not a player

1 comment

0

yeah sorry for necro but i need it too so did you fixed?

This discussion is preserved as it was. New answers, comments, and votes are closed.