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

Part not running Ontouch function?

Hello! I want to make the player heal when touching a part. But the code is not working This is the code:

function onTouched(hit)
	hit.Parent:WaitForChild('Humanoid').Health += 15
end
script.Parent.Touched:connect(onTouched)

5 comments

0

Which script is this? Also, make sure your health is below or equal to 85 to see changes.

0

Also, can you show me what's the error?

0

there is no error

0

need some sort of check or debounce

0

:connect is deprecated please use :Connect

2 answers

The only problem is that it might be in a local script. If it is, change it to a normal script. or if that doesn't work, change it to

function onTouched(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
      hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health +15
end
script.Parent.Touched:connect(onTouched)

I know exactly what is causing the problem. Replace the script with the following:

function onTouched(hit)
	local health = hit.Parent:WaitForChild('Humanoid').Health.Health
	health = health+15
end
script.Parent.Touched:connect(onTouched)

I hope that helps :D

1 comment

0

this does not work ):

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