Hello everybody, I'm trying to make a health pad script kind of like in fencing, but it wont work so if you could respond with a answer it would be greatly appreciated.
function onTouch (hit) game.Players.LocalPlayer.Humanoid.Maxhealth = 200 game.Players.LocalPlayer.Humanoid.Health = 200 end script.Parent.Touched:Connect(onTouch)
(i've only been scripting for 2-3 years so i'm kind of still new.)
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") -- Does not really matter what type of value it is because only the name matters 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) -- This will delete the tag in 15 seconds
function onTouch (hit) game.Players.LocalPlayer.Character.Humanoid.MaxHealth = 200 game.Players.LocalPlayer.Character.Humanoid.Health = 200 end script.Parent.Touched:Connect(onTouch)
Humanoid isn't in the Players thing, it is in the player model in Workspace, so you have to do .Character