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

How to get more Hp after the level up ?

I don't know why this script didn't work.

LocalScript location StarterPlayer/StarterCharacterScript

local Lvl = game.Players.LocalPlayer:FindFirstChild("Level") --I try to use "Lvl" but this didn't work too.
local Char = script.Parent
local humanoid = Char:WaitForChild"Humanoid"
if Lvl.Value == Lvl.Value +1 then
	humanoid.MaxHealth.Value = humanoid.MaxHealth.Value *1.1
	humanoid.Health.Value = humanoid.MaxHealth.Value
	print("Test")
end

I try to find "Level" from leaderstats. I want to after geting lvl to change MaxHealth

1 comment

0

I'm still new but i'm pretty sure Level and Lvl is not part of Players so you can't use the FindFirstChild for that

1 answer

✓ Accepted answer
  1. You are trying to find the "Level" stat in the Player itself, not in the leaderstats model.
  2. The if statement at Line 4 can never return true because Lvl.Value can never be the same as the Lvl.Value + 1; It will always be one more.
  3. You forgot the parenthesis at the WaitForChild() function in Line 3

Edit: You need to leave away the ".Value" at "Health" and "MaxHealth" (see comment)

local stats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local Lvl = stats:FindFirstChild("Level")
local oldLvl = Lvl.Value --We will store the current level in a variable

local Char = script.Parent
local humanoid = Char:WaitForChild("Humanoid")

while true do --You probably want this permanent loop to constantly keep checking if the player levelled up.
	if oldLvl == Lvl.Value - 1 then --If the old level is the same as the new level - 1 (if the player levelled up, ) then continue
		oldLvl = Lvl.Value --Change the old level to the current level to start the cycle again
		humanoid.MaxHealth = humanoid.MaxHealth * 1.1
		humanoid.Health = humanoid.MaxHealth
		print("Test")
	end
	wait()
end

If there are any errors, I will be happy to help! :)

2 comments

0

MaxHealth does not change and Test do not write on output.

0

Whoops, I just realised, that you can leave away the ".Value" in "MaxHealth.Value" because ".Value" is it's own property only used for Value instances (StringValue, IntValue, etc.) That should do the trick! :)

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