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

Player health not scaling with level value?

Asked by 4 years ago

In the game I am currently working on, health is determined by armor and level. Armor doesn't exist yet, so right now it's just level. It always shows at 99/99 health, so the game probably thinks that your level is always 0, sometimes even thinks ur lvl 1. Heres the code.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Stats = Player:WaitForChild("leaderstats")
        local Level = Stats:WaitForChild("Level")
        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.MaxHealth = (Level.Value*10)+99
        Humanoid.Health = Humanoid.MaxHealth
    end)
end)

Not sure what's wrong with it, but here it is. If you can help, please do. I will accept the answer as soon as I know it works, thanks!

1 answer

Log in to vote
1
Answered by
Geobloxia 251 Moderation Voter
4 years ago
Edited 4 years ago

Put a wait(2) after the CharacterAdded function to wait for the humanoid to load in. Even though you put the WaitForChild("Humanoid"), it will not work properly because the character isn't loaded so it can't find a child inside a parent that hasn't loaded in yet. Like this:

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
    wait(2) -- Cooldown
        local Stats = Player:WaitForChild("leaderstats")
        local Level = Stats:WaitForChild("Level")
        local Humanoid = Character:WaitForChild("Humanoid")

        Humanoid.MaxHealth = (Level.Value*10)+99
        Humanoid.Health = Humanoid.MaxHealth
    end)
end)
0
I tried that, but ill try again in a bit. Also, I meant to make it ^3, but whatever *10 is fine Trisodin529 89 — 4y
0
Can I see the leaderstats script? Geobloxia 251 — 4y
0
Yep, it works. No need to see the script, I only did a wait(1). Thanks! Trisodin529 89 — 4y
0
You're welcome! :D Geobloxia 251 — 4y
Ad

Answer this question