I made this script that's suppose to give the player more maxhealth based on their strength so a player with 1000 strength will have more health than someone with 10 strength. Everything works fine except when the player dies or resets their health goes back to 100/100 and the way to fix this is by gaining more strength then their health goes to what it should be.
Here's the 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 * 1.25 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 = DefaultHealth * Strength.Value * 1.25 end) end) end end)
I have a healthbar that shows the health going to 100/100 after the player dies so if it could be something wrong in the gui's script let me know if i should post that script here aswell
edit: ok i've tested it and the gui is fine.
You would need to set the humanoid MaxHealth and Health when you detect Humanoid.Dead
signal and Player.CharacterAdded
signal. (You might need to use WaitForChild on Humanoid because HumanoidRootPart load first)
hum.Died:Connect(function() char:WaitForChild("Humanoid").MaxHealth = DefaultHealth * Strength.Value * 1.25 -- Since char will automactically yield for the CharacterAdded event, safely use this way end