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

How do i make a player gain more Health when they level up?

im creating a rpg called BaconRPG im using a startercharacter that changes you into a bacon hair, if that changes anything

heres the script i made, btw i dont know how to do anything with scripting

local lvl = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lvl
local player = game.Players.LocalPlayer
local char = player.Character

char.Humanoid.MaxHealth = 100 +(lvl * 10)


char.Humanoid.Health = 100 +(lvl * 10)

2 comments

0

You want to be doing this on the server with a changed event for lvl

0

i have lvl as a leaderstat

2 answers

You have to write lvl.Value and not just lvl:

local lvl = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lvl
local player = game.Players.LocalPlayer
local char = player.Character
 
char.Humanoid.MaxHealth = 100 +(lvl.Value * 10)
 
 char.Humanoid.Health = 100 +(lvl.Value * 10)

1 comment

0

it still isnt working

Now this script only runs once, which is why the health isn't going up. To fix this, I would recommend adding a .Changed event that checks for any changes on the lvl value. I would also recommend doing this on a server script, preferably the script that handles creating the leaderstats.

in a server script:

game.Players.PlayerAdded:Connect(function(Player)

	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = Player

	local lvl = Instance.new("IntValue")
	lvl.Name = "Lvl"
	lvl.Parent = stats

	lvl.Changed:Connect(function()
		local char = Player.Character or Player.CharacterAdded:wait()
		local Humanoid = char:WaitForChild("Humanoid")
		Humanoid.MaxHealth = 100 + (lvl.Value * 10)
		Humanoid.Health = Humanoid.MaxHealth
	end)

end)

This script checks for any property change in "lvl" and if there is, adds to the the humanoid's maxhealth.

I hope this helps.

2 comments

0

i have already made script that mkaes the leaderstats and this didn't work

0

I know you already made a script that makes the leaderstats, I was showing here how you'd implement it. Are you changing the lvl value? I tested this myself and it was fully functional.

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