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

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

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

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

1 comment

0

I did the changes and nothing happens but I am pretty sure this was part of the problem

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

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