Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Player health not scaling with level value?

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

✓ Accepted answer

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)

4 comments

0

I tried that, but ill try again in a bit. Also, I meant to make it ^3, but whatever *10 is fine

0

Can I see the leaderstats script?

0

Yep, it works. No need to see the script, I only did a wait(1). Thanks!

0

You're welcome! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.