✓ Accepted answer
In your script you are getting the LocalPlayer which is you cannot do in a server script and that is only the player not the character so you cannot get the humanoid from it. Instead you can use the hit argument in your onTouch function to get the humanoid. hit is the object that it touched so if a players leg touched it you can say hit.Parent to get the character and then get the humanoid inside of the character. You should always check if the thing touching it is a character by checking if they have a humanoid so it does not error because it can tell if other things are touching it like another part.
function onTouch (hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.MaxHealth = 200
humanoid.Health = 200
end
end
script.Parent.Touched:Connect(onTouch)
I would also recommend that you check if the character has already used the health pad so they are not able to heal infinitely. You could do that by adding a value to the character and the next time that character touches they pad check if they have that value.
function onTouch (hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and not hit.Parent:FindFirstChild("TouchedHealthPad") then
local tag = Instance.new("BoolValue")
tag.Name = "TouchedHealthPad"
tag.Parent = hit.Parent
humanoid.MaxHealth = 200
humanoid.Health = 200
end
end
script.Parent.Touched:Connect(onTouch)
If you would like the player to be able to get the boost from the health pad again after some time then you can add this after creating the tag:
game.Debris:AddItem(tag, 15)
6 comments
And which line would i put game.Debris:AddItem(tag, 15) on?
you would put it right after tag.Parent = hit.Parent
Hmm, I did that and whenever the bool value goes away the first time, i touch the hit pad on 1 hp and only just gives me the bool value again.
Is there a way i could modify the script to use debounce instead?
I just tested and it does work. I assume you are changing the health of the humanoid while in studio playing the game and that only changes it on the client not the server. You have to make sure you are in server mode before you change the health.
ok, thanks.