Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(Solved)Im trying to make a script that changes your hp based on your level, code doesnt work. help?

Asked by
das1657 20
3 years ago
Edited 3 years ago

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

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function(character)
        character.Humanoid.MaxHealth = player.leaderstats.Level * 20
        character.Humanoid.Health = player.leaderstats.Level * 20
    end)
end

An explanation on why it doesnt work would be helpful as I am a noob at scripting

2 answers

Log in to vote
0
Answered by
das1657 20
3 years ago

Fixed it myself

Put the script in starterplayerscripts

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)



character.Humanoid.MaxHealth = player.leaderstats.Level.Value * 20
character.Humanoid.Health = player.leaderstats.Level.Value * 20
Ad
Log in to vote
0
Answered by
dxrrevn 13
3 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an answer.

Change player.leaderstats.Level to player.leaderstats.Level.Value. That should most likely work. If not, then I'm unsure on how to help.

0
I did the changes and nothing happens but I am pretty sure this was part of the problem das1657 20 — 3y

Answer this question