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

Whats wrong with my script its supposed to add 5 health and .5 walk speed every time you level up?

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)                                             

3 comments

0

You haven't given us much to work with... Is there anything indicating what the problem might be?

0

it doesnt increase your speed or your health

0

Also, you say the health and walk speed should be changed when a player levels up, but it seems there is nothing in the script to indicate this is actually being done

1 answer

✓ Accepted answer

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)      

1 comment

0

Thank You! This really helped me.

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