Alright so, I have a health bar connected to a level up system, every time you level up you got 20+ max health, health heals over 100+ (many people have had issues with this), when you join if you have 200 health your health automatically sets to 200, what I’m having problem with is when you reset you spawn with 100 health then gradually heal to your max health:
Here is a code I used:
local Player = game.Players.LocalPlayer
local Char = Player.Character
Char:WaitForChild("Humanoid").Died:Connect(function()
wait(4)
local Char = Player.Character
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
Char.Humanoid.Health = Char.Humanoid.MaxHealth
spawn(function()
while true do
wait(0.4)
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
end
end)
end)
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Wait()
local function UpdateHealth(Humanoid)
Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
Humanoid.Health = Humanoid.MaxHealth
end
game.Workspace.ChildAdded:Connect(function(Child)
if Child.Name == Player.Name then
local Character = Child
local Humanoid = Character:WaitForChild("Humanoid", 30)
if Humanoid ~= nil then
UpdateHealth(Humanoid)
end
end
end)
local Event = game.ReplicatedStorage:WaitForChild("HealthChange")
game.Players.PlayerAdded:Connect(function(Player)
wait(4)
local Char = Player.Character
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
Char.Humanoid.Health = Char.Humanoid.MaxHealth
spawn(function()
while true do
wait(0.4)
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
end
end)
end)
Event.OnServerEvent:Connect(function(Player)
local Char = Player.Character
Player.Stats.HealthExp.Value = Player.Stats.HealthExp.Value + 2
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
local Char = Player.Character
Char.Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
local healStep = Char.Humanoid.MaxHealth * 0.012
wait(4)
Char.Humanoid.Health = Char.Humanoid.Health + healStep
end)
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Wait() -- This is where the error popped up
local function UpdateHealth(Humanoid)
Humanoid.MaxHealth = Player.Stats.HealthLevel.Value * 20 + 80
Humanoid.Health = Humanoid.MaxHealth
end
game.Workspace.ChildAdded:Connect(function(Child)
if Child.Name == Player.Name then
local Character = Child
local Humanoid = Character:WaitForChild("Humanoid", 30)
if Humanoid ~= nil then
UpdateHealth(Humanoid)
end
end
end)
i already tested my script it works when i substitue healthlevel.value for 10 or anynumber(that was probably just your health increasing), but you can try this script