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

How come I'm unable to change a Players health?

Asked by 2 years ago
Edited 2 years ago

I currently have a vest system and it should be setting the health when a player has a vest but for some reason, it just won't work at all it works perfectly fine without doing that but while doing it it won't work at all what is going on?

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAppearanceLoaded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")

        ---PlayerHealth
        local MaxHealth = Humanoid.MaxHealth
        local Health = Humanoid.Health

        ---Vests
        local Vests = {

            ["TanVest"] = Character:FindFirstChild("TanVest");
            ["BlackVest"] = Character:FindFirstChild("BlackVest");
        }

        ---VestLocator
        local charChildren = Character:GetChildren()

        local tanVest = table.find(charChildren, Vests.TanVest)
        local blackVest = table.find(charChildren, Vests.BlackVest)

        if tanVest then --This without the math works fine but with the math wont, same fo the elseif
            Health = 150
            MaxHealth = 150
            print("Player has a TanVest")
        elseif blackVest then
            print("Player has a BlackVest")
            Health = 200
            MaxHealth = 200
        else
            print("Player has no vest")
        end
    end)
end)
0
did you look in the output? no errors? Persona3_FES 2 — 2y
0
None vincentthecat1 199 — 2y
0
maybe it doesnt trigger it for some reason? ive had the exact same problem some times, but ive noticed it only happened with LocalScripts. are you using a LocalScript? if so, you could probably benefit from using RemoteEvent:OnServerInvoke for that player. Persona3_FES 2 — 2y
0
I'm using a normal script vincentthecat1 199 — 2y
View all comments (2 more)
0
well, then, maybe you could use the reverse?: remoteEvent:OnClientEvent:connect() and in the ServerScript: remoteEvent:FireClient() Persona3_FES 2 — 2y
0
I actually tried that as a solution and it never did set the health and if I tried to do something like that for the if and elseif it wouldn't work like at all no text would be printed stating the vest a player has on vincentthecat1 199 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

you must humanoid.Maxhealth = 150 not maxhealth = humanoid.maxhealth , maxhealth = 150 this is a mistake of beginner scripter if you write maxhealth = 150 it just change the variable but you write humanoid.maxhealth it change value

Ad

Answer this question