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.
local DefaultHealth = 100 game.Players.PlayerAdded:Connect(function(player) local Stats = player:WaitForChild("leaderstats") local Strength = Stats:FindFirstChild("strength") local char = player.Character or player.CharacterAdded:wait() if char then local hum = char:FindFirstChild("Humanoid") if hum then hum.MaxHealth = DefaultHealth * Strength.Value end end 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:
local DefaultHealth = 100 game.Players.PlayerAdded:Connect(function(player) local Stats = player:WaitForChild("leaderstats") local Strength = Stats:FindFirstChild("strength") local char = player.Character or player.CharacterAdded:wait() if char then local hum = char:FindFirstChild("Humanoid") if hum then hum.MaxHealth = DefaultHealth * Strength.Value end Strength.Changed:connect(function(value) if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.MaxHealth = DefaultHealth + Strength.Value * 1.25 end player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").MaxHealth = 100 + Strength.Value * 1.25 end) end) end end)