You could put in a print statement and get the values of maxchi and healthmultiplier before you compute hum.MaxHealth and hum.Health. Maybe they aren’t being set correctly and it sets your players health to 0.
It sounds like the issue may be related to the player’s health being set to zero upon loading into the game. One possible solution to prevent the player from dying upon loading in is to delay the execution of the player’s health and max health setter code by a short amount of time after the player spawns in the game. You can do this using a Wait() function.
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
-- Wait briefly to make sure the character is fully loaded
wait(1)
local hum = char:WaitForChild("Humanoid")
local maxchi = player:WaitForChild("Stats"):WaitForChild("MaxChi")
local healthmultiplier = player:WaitForChild("Upgrades"):WaitForChild("HealthMultiplier")
hum.MaxHealth = (100 + maxchi.Value / 200) * healthmultiplier.Value
hum.Health = (100 + maxchi.Value / 200) * healthmultiplier.Value
maxchi.Changed:Connect(function()
hum.MaxHealth = (100 + maxchi.Value / 200) * healthmultiplier.Value
end)
end)
end)
wait is actually deprecated but still there for backward compatibility so you should be using task.wait instead. An arbitrary time to wait could still causes issues, you might consider this line of code instead: