It use to work but now it doesn't
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*5)+100 Humanoid.Health = Humanoid.MaxHealth Humanoid.WalkSpeed = (Level.Value*.5)+16 Humanoid.Health = Humanoid.MaxHealth end) end)
As your code is currently, both the speed and health of your character is scaled according to your level every time Player.CharacterAdded
is fired, which means that it changes only when you spawn into the game or respawn after you die.
In order to make your character change whenever you level up, you must attach some kind of event to the changing of your player's level stat, such as the :GetPropertyChangedSignal
method, which I will use in the updated version of 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") -- Leave this here so health and walkspeed is set when your character loads Humanoid.MaxHealth = (Level.Value*5)+100 Humanoid.Health = Humanoid.MaxHealth Humanoid.WalkSpeed = (Level.Value*.5)+16 Level:GetPropertyChangedSignal("Value"):Connect(function() -- Fires whenever a change is made to the value of the level stat -- Change health and walkspeed every time your level changes Humanoid.MaxHealth = (Level.Value*5)+100 Humanoid.Health = Humanoid.MaxHealth Humanoid.WalkSpeed = (Level.Value*.5)+16 end) end) end)