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

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

Asked by 4 years ago

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)

0
You want to be doing this on the server with a changed event for lvl User#5423 17 — 4y
0
i have lvl as a leaderstat Ninjalord1003 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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)

0
it still isnt working Ninjalord1003 2 — 4y
Ad
Log in to vote
0
Answered by
Kyokamii 133
4 years ago

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.

0
i have already made script that mkaes the leaderstats and this didn't work Ninjalord1003 2 — 4y
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. Kyokamii 133 — 4y

Answer this question