How come this max health script wont work?
Asked by
5 years ago Edited 5 years ago
This script makes it so when the remove event is fired you gain "Defense" and the more defense you have the higher your max health is.. But for some reason when a brand new player joins when they go to Fire said event their max health goes to 0 then when they do it again their max health goes up by 500(Which is what is suppose to happen)
OnServerEvent
01 | local event = game.ReplicatedStorage:WaitForChild( "Def" ) |
02 | local DefaultHealth = 100 |
04 | event.OnServerEvent:Connect( function (player) |
05 | local Stats = player:WaitForChild( "Stats" ) |
06 | local Strength = Stats:FindFirstChild( "Defense" ) |
07 | local char = player.Character or player.CharacterAdded:wait() |
09 | local hum = char:FindFirstChild( "Humanoid" ) |
11 | hum.MaxHealth = DefaultHealth * Strength.Value |
12 | Strength.Value = Strength.Value + 5 |
As shown by the video theres a new player, when they go to train there defense, their max health goes down to 0 but when they train it again the max health goes up by 500 on each press.
https://gyazo.com/64a8006cd5bea44eb3d8b709b43c7174
How do i make it so the player's health doesn't go down to 0?