Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part not running Ontouch function?

Asked by 3 years ago

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)
0
Which script is this? Also, make sure your health is below or equal to 85 to see changes. Gabe_elvin1226aclan 323 — 3y
0
Also, can you show me what's the error? Gabe_elvin1226aclan 323 — 3y
0
there is no error NoobPowerPlayzz 15 — 3y
0
need some sort of check or debounce matiss112233 258 — 3y
0
:connect is deprecated please use :Connect Gabe_elvin1226aclan 323 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

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

0
this does not work ): NoobPowerPlayzz 15 — 3y

Answer this question