I want to make it so when a player gains strength their health also goes up. I'm a new scripter so I have no idea what I'm doing and I'm stuck.
This is what i tried so far but the health does no go up, nothing in output either.
01 | local DefaultHealth = 100 |
02 |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | local Stats = player:WaitForChild( "leaderstats" ) |
05 | local Strength = Stats:FindFirstChild( "strength" ) |
06 | local char = player.Character or player.CharacterAdded:wait() |
07 | if char then |
08 | local hum = char:FindFirstChild( "Humanoid" ) |
09 | if hum then |
10 | hum.MaxHealth = DefaultHealth * Strength.Value |
11 | end |
12 | end |
13 | end ) |
update: I had this script above in a local script under starter character so i moved it into a script under server script and when i tested, the players maxhealth went to 0.
If you have a script that doesn't increase the strength value, the value is being multiplied by zero. Add a script that increases the strength value, and you might be rid of the error.
Got it working, thanks for the help.
updated script:
01 | local DefaultHealth = 100 |
02 |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | local Stats = player:WaitForChild( "leaderstats" ) |
05 | local Strength = Stats:FindFirstChild( "strength" ) |
06 | local char = player.Character or player.CharacterAdded:wait() |
07 | if char then |
08 | local hum = char:FindFirstChild( "Humanoid" ) |
09 | if hum then |
10 | hum.MaxHealth = DefaultHealth * Strength.Value |
11 | end |
12 |
13 | Strength.Changed:connect( function (value) |
14 | if player.Character and player.Character:FindFirstChild( "Humanoid" ) then |
15 | player.Character.Humanoid.MaxHealth = DefaultHealth + Strength.Value * 1.25 |