Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Heal Bricks Won't Work with my avatar?

Asked by 5 years ago

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!

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

0
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! Notrealac0unt 19 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

0
I know this will sound bad but it didn't work, Is there a setting I'm missing? Did I disable something? Notrealac0unt 19 — 5y
0
So I go in Studio, go to my Humanoid, make the health 5 (Max is 100) then walk on the brick. Nothing happens. Notrealac0unt 19 — 5y
0
Oh if you wanna heal to max health then all you gotta do is use h.Health = h.MaxHealth Protogen_Dev 268 — 5y

Answer this question