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.
2 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
4 | humanoid.MaxHealth = 200 |
9 | 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.
02 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
03 | if humanoid and not hit.Parent:FindFirstChild( "TouchedHealthPad" ) then |
04 | local tag = Instance.new( "BoolValue" ) |
05 | tag.Name = "TouchedHealthPad" |
06 | tag.Parent = hit.Parent |
08 | humanoid.MaxHealth = 200 |
13 | 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:
1 | game.Debris:AddItem(tag, 15 ) |