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

Why won't my character's max health change based on a certain stat?

Asked by 5 years ago
Edited 5 years ago

I made stats like stamina, mana, etc. the max stamina and max mana worked perfectly, whenever you added a stat point, the max went up, but for some reason, It doesn't change the humanoid's max health, it doesn't show any errors or anything, it just does nothing to the humanoid health.

Script:

local player = game.Players.LocalPlayer
local health = player:WaitForChild("Stats"):WaitForChild("Health")
local playerhealth = player.Character:WaitForChild("Humanoid").Health
local maxhealth = player.Character:WaitForChild("Humanoid").MaxHealth
local stats = player:WaitForChild("Stats")
local expmax = stats:WaitForChild("ExpMax")
local level = stats:WaitForChild("Level")
local stamina = stats:WaitForChild("Stamina")
local maxstam = stats:WaitForChild("MaxStam")
local stamstat = stats:WaitForChild("StaminaStat")
local durability = stats:WaitForChild("Durability")
local magic = stats:WaitForChild("Magic")
local maxmana = stats:WaitForChild("MaxMana")

while wait(0.01) do
    health.Value = playerhealth
    expmax.Value = level.Value * 100
    maxstam.Value = stamstat.Value*2 + 100
    maxmana.Value = magic.Value*2 + 100
    maxhealth = durability.Value*2 + 100
end

I've tried simply putting the durability part in another script, but it still does the same thing, if you have any idea what's wrong, please let me know, because I need this to work for my friends game. Once again, it doesn't show any errors, warnings, etc. so I have no clue where to start.

0
oh on the maxstam.Value = stamstat.Value2 it's supposed to say * 2 it acidently changed the text. Knineteen19 307 — 5y
0
Put your code inside a code block. Edit this post, click on the blue Lua icon and two lines of "~~~" will appear. Put your code in between these. xPolarium 1388 — 5y
0
How do I edit the post, sorry it's my first time here. Knineteen19 307 — 5y
0
wait nevermind, figured it out Knineteen19 307 — 5y
View all comments (2 more)
0
You cannot use LocalPlayer in a Script. This is client side only. xPolarium 1388 — 5y
0
This is a local script inside of starter player scripts, and the thing is, everything in this script works, except the max health change. Knineteen19 307 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

First of all, MaxHealth is a property of the humanoid. So at line 4 you set maxhealth to whatever the humanoid's MaxHealth currently is (probably 100). Then in the loop you change maxhealth to another number. This is a common mistake.

If you want to change the value of the humanoid's MaxHealth, you should do something like this:

local humanoid = player.Character:WaitForChild("Humanoid")
-- (removed not relevant code)
humanoid.MaxHealth = durability.Value*2 + 100

Another issue: you can't modify anything in the workspace from a LocalScript. It will not replicate to the server. If you need a tutorial on client-server comunication, see this.

0
That last thing you said is wrong. The client isn't 100% limited. Player physics are replicated. User#19524 175 — 5y
0
Thanks! Sorry for the late reply, but it worked, I'll keep that in mind from now on. Knineteen19 307 — 5y
Ad

Answer this question