Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How do I script it so the max health is always = to a leaderstat?

Asked by 2 months ago

What evert he leaderstats is or if it even changes I want the maxhealth of a player to equal to it. Ive tried many things but I can't seem to change the max health being always = to a leaderstat. My leaderstat script is fine.

0
Please provide your code so we can better understand you. If you don't have any code, then your question might be moderated Cynical_Innovation 577 — 2mo

2 answers

Log in to vote
1
Answered by
Avoxea 43
2 months ago
Edited 2 months ago
local yourplayer = --fill this in
local yourleaderstat = --fill this in
local stat = game.Players[yourplayer].leaderstats[yourleaderstat]

stat:GetPropertyChangedSignal("Value"):Connect(function(val)
     yourplayer.Character.Humanoid.MaxHealth = stat.Value
    yourplayer.Character.Humanoid.Health = stat.Value
end)

It is difficult to provide a script for you since we have no reference as to what your system is doing, but this may help you.

0
I will check it out. THUNDER_WOW 149 — 2mo
Ad
Log in to vote
0
Answered by 2 months ago
Edited 2 months ago

You could use :GetPropertyChangedSignal on your LeaderStatValue to determine when it the Value has changed like so:

LeaderStatMaxHealth:GetPropertyChangedSignal("Value"):Connect(function()
    print("Value has changed")
end)

Edit: Since I'm unsure on how comfortable with this you might be I'll link you to an article. https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal

0
I have tried that, lets say the stat was 200 even with that function the players max health would stay at 100 no matter what. THUNDER_WOW 149 — 2mo
0
It sounds like your doing something wrong then. It would be much easier to help you out if you provided a script. PURGATORYAGENT_1 43 — 2mo
0
I know that I am not doing something wrong. THUNDER_WOW 149 — 2mo

Answer this question