My script is supposed to change your health and maxhealth based on how high your level is, however it doesnt do anything when I spawn in the game
1 | local function onPlayerAdded(player) |
2 | player.CharacterAdded:Connect( function (character) |
3 | character.Humanoid.MaxHealth = player.leaderstats.Level * 20 |
4 | character.Humanoid.Health = player.leaderstats.Level * 20 |
5 | end ) |
6 | end |
An explanation on why it doesnt work would be helpful as I am a noob at scripting
Fixed it myself
Put the script in starterplayerscripts
1 | local character = script.Parent |
2 | local player = game.Players:GetPlayerFromCharacter(character) |
3 |
4 |
5 |
6 | character.Humanoid.MaxHealth = player.leaderstats.Level.Value * 20 |
7 | character.Humanoid.Health = player.leaderstats.Level.Value * 20 |
Change player.leaderstats.Level to player.leaderstats.Level.Value. That should most likely work. If not, then I'm unsure on how to help.