Why wont this heal the player?

Oh, not to worry, I would still opt to use the Parent property though because you could have a part buried deep inside a model which would then trigger the event to fire if touched (unless the Humanoid instance check was also added).

Further there’s a slight difference, the script from @GhostShinjiro will also detect when it’s touched by a hat for example, while what I sent will only detect if the direct Parent of the part is the player’s character, which is true for all bodyparts, but not for hats

1 Like

Do you mean the part instance named “Handle” which belongs to the Accessory instance? As accessories themselves do not have a “Touched” event.

Idunno why everyone is overcomplicating things

local function ApplyTouchedEvent(Activator)
	local Ev
	Ev = Activator.Touched:Connect(function(hit)
		local Hmn = hit.Parent:FindFirstChild("Humanoid") --Use FindFirstChild instead of WaitForChild in cases like this
		if Hmn and Hmn.Health < Hmn.MaxHealth then
			Hmn.Health += 10 --Short for Hmn.Health = Hmn.Health + 10
			Ev:Disconnect() -- or the touched event automatically gets disconnected if the Activator object is destroyed
		end
	end)
end

while wait(3) do
--blahblah
	ApplyTouchedEvent(Activator)
end

Alternatively, if you just want it to apply to players, you can do if game.Players:GetPlayerFromCharacter(hit.Parent) then

1 Like

Yeah! i added the humanoid checker just now.

Humanoids, along with other body parts, need a parent that is a Model. So I don’t think you would need to worry about that. But I haven’t worked with custom characters so take this with a grain of salt.

1 Like

This is true, unless for some weird reason you have a rogue moving part (not inside a model) with a Humanoid instance parented to it.

2 Likes