So I've been trying this for 30 minutes and feel dumb as the script is supposed to heal you,
script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") hum.Health = hum.Health + 100 end)
Any help is appreciated as tutorials are doing the SAME exact thing but it's not working for me. Also, it's R15 Thanks!
One of the problems here is that you aren't checking if the humanoid exists, thus , it will throw an error whenever it touches a part who's parent doesnt have a child named Humanoid
.
A simple fix for this would to add in a check whether if hit.Parent contains a humanoid.
script.Parent.Touched:Connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then hum.Health = hum.Health + 100 end end)
this prevents the possibility that it is just a random part touching the brick and instead of the character.
Another thing to note is that you should use the GetPlayerFromCharacter
function if you want it to work for just players and not NPCs
Another factor of this is the Accurate Studio
update. Which essentially brings Network Filtering to roblox studio. A reason this could be a problem for you is that if you modify the health of a player locally (when the screen has a blue border), it wont replicate to the server.
However, as the script in question is a server script, it will think that the player's health is still same as the maxhealth, thus not modifying the health.
To get modify the player/npc's health on the server, simply press the button on the topbar labeled Current Client
to access the server, then procede to modify the character's health from the command bar there.
Bear in mind here that the command bar isn't always running on the server, when you are on the client it is client sided, when you are on the server , it is server sided.
Hopefully this Helped!
Your forgetting to check to see if said humanoid exists.
script.Parent.Touched:Connect(function(hit) local p = game.Players:GetPlayerFromCharacter(hit.Parent) if p then local h = hit.Parent:FindFirstChild("Humanoid") if h then h.Health = h.Health + 100 end end end)
That will work for ya