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!
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)