Hey,
I'm creating an RPG-styled game, and I modify the player's HP every time they level up. However, when they die, the HP resets and goes back to the default 100.
Here is the code:
local replicatedStorage = game:GetService("ReplicatedStorage")
local hpEvent = replicatedStorage:WaitForChild("HpEvent")
local hpDeath = replicatedStorage:WaitForChild("HpDeathChange")
function changeHP(player, value)
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
-- Checks if the player isn't dead
repeat wait() until humanoid.Health ~= 0
repeat wait() until player.leaderstats.Level.Value == value
print("yes")
local health = 100 + (value ^ 2.5 + value * 40)
local flooredHealth = math.floor(health)
humanoid.MaxHealth = flooredHealth
humanoid.Health = flooredHealth
end
hpEvent.OnServerEvent:Connect(changeHP)
I have a remote even that fires once the player dies & levels up!
