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

How to get more Hp after the level up ?

Asked by 5 years ago

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

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 TheOneKingx 7 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
  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! :)

0
MaxHealth does not change and Test do not write on output. Yakubovsky69 5 — 5y
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! :) Thomanski 15 — 5y
Ad

Answer this question