Need Help at making a custom Event

Hello people, i am kinda new to scripting , what i want to achieve is in title , so ill give an example to explain what i mean about custom events → example : CharacterAdded & Chatted & RenderStepped. I want to make a custom event for Humanoid for when Humanoid’s health reaches 90 ( i know there is an event when health changes but what i want is how to make a custom event )

1 Like

You can’t add custom events/properties (not attributes)/methods to instances directly. You can make something that looks like a custom event with bindable events, but it wont be like this:

Humanoid.CustomHealthChanged:Connect(function() end)

This post might help you?

1 Like
-- Variables 
local Player = game.Players.LocalPlayer 
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid  = Character:WaitForChild("Humanoid") 

local Event = Path.To.BindableEvent 

-- Functionality 
Humanoid.HealthChanged:Connect(function(Health)
    if Health == 90 then 
         Event:Fire(Humanoid) -- This would only fire on the client side of the engine, if you want it to run on the server you need to fire the event on the server (so this event -> RemoteEvent -> Bind)
    end 
end)
1 Like

I don’t encourage making custom events as value checking the health value in the healthchanged event is the most reliable and secure way.

This is the best way of doing it but if you want the event to fire if the health is equal to 90 OR MORE then change Health == 90 to Health >= 90 which changes the operator from “Equal to” to “Greater than or equal to”

1 Like

I should really appreciate your help , the post you’ve just provided me helped me with my request :slight_smile: .

2 Likes

Thanks for this , this also helped me to understand bindable events more :+1:

2 Likes