✓ Accepted answer
Checks
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
Client Server Seperation
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!
1 comment
Yes that was it, it wasn't going through the server so it didn't change it's health value even though it looked like it in studio. The script works to thanks!