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

How Do I fire a remote event after my NPC health is 0?

Hi, so I have a normal script inside of an NPC/rig and I want that script to fire a remote event So that my quest GUIs value on the screen will change to 1 and I really need help with this.When ever I try and fire a remote event it says that I need a player function when I have the function connected to the player funtion.Yet any other script works like if I want to print Hi.

Normal script:

local Humanoid = script.Parent.Humanoid
local event = game.ReplicatedStorage:WaitForChild("Human1") 

Humanoid.Died:Connect(function(player)
	event:FireClient(player)
end)

Human one is The name for my remote event

2 comments

0

Is the script inside a player or an NPC?

0

It is inside of the NPC

3 answers

You could try to check the Humanoids health instead of the function. Such as:

local hum = --your humanoid

if hum.Health == 0 then --checks if the Humanoid's health is 0
event:FireClient(player)
end)

I hope this helped c:

1 comment

0

The calling of the player needs to first be definded in the function so it is not working because it does not know how to fire

Humanoid.Died does not pass the Player

Humanoid.Died

8 comments

0

Does that mean that I need to not just do the event of it dying but having to reference the propertie of its health instead

0

One way of doing it is to have a creator tag(ObjectValue with the Player as value) created when a Player damages it and get the killer from that

0

Another way is storing all Players that have dealt damage to it in a table(Probably above your skill level though)

0

How would I do that? 

0

The setting the object value with the player as the value

0

In all thingys that deal damage get the Player using it and create an ObjectValue with Instance.new then set ObjectValue.Value = Player

0

also, set the Name to creator or whatever name you want to use for it

Store a script inside a humanoid. I'm assuming that you want to do something on the server's side so instead of using a remote event to fire a client, use a Bindable Event. Bindable Events are basically remote events, but for two servers talking to each other. You will also need to use a .Changed event too. If you want to use a remote event, then do the same thing in this script, but with a remote event. TIP: You can use a BindableEvent in the same script.

script.Parent.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	BindableEvent:Fire()
end)

BindableEvent.Event:Connect(function()
	-- Event
end)

2 comments

0

I meant to say character! Sorry!

0

It is not working Bc I need to fire a remote event to a local script(hence why it needs to be a remote event)

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