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

Is there a onEquipped event on roblox?

Hi, I made this script,

-- Made by KenzaShadow --
local HealBall = script.Parent
function onEquip()
	local Player = game:GetService'Players'.LocalPlayer
	if (Player ~= nil) then
		Player.Humanoid.MaxHealth = 200
		wait(1)
		Player.Humanoid.Health = Player.Humanoid.MaxHealth
	end
end
HealBall.Equipped:connect(onEquip)

and the Output says, "Equipped is not a valid member of part" The Handle is this scripts parent, and The Handle's Parent is a Tool Instance. Thanks for the Help.

2 answers

✓ Accepted answer

The Equipped event is fired on the Tool, not the Handle.

Also, the player's Humanoid is located in their character, not the actual player. You can access the Character using the Character property of the player.

Fixed Code:

-- Made by KenzaShadow --
local HealBall = script.Parent
function onEquip()
    local Player = game:GetService'Players'.LocalPlayer
    if (Player ~= nil) then
        Player.Character.Humanoid.MaxHealth = 200 --The character's humanoid, not the player's.
        wait(1)
        Player.Character.Humanoid.Health = Player.Humanoid.MaxHealth --The character's humanoid, not the player's.
    end
end
HealBall.Parent.Equipped:connect(onEquip) --The Handle's parent.

If I helped you out, be sure to accept my answer!

2 comments

0

Thanks, but I want to know how to connect a function to a Equip event E.g, "script.Parent.Touched:connect(function(..."

0

I answered your other question.

Equipped is not an event for Parts, because you don't equip Parts. It's an event for Tools. Therefore you just have to use the tool to access the event.

local HealBall = script.Parent.Parent

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