Maybe try a loop to see the player’s current health? What I see is that you are setting the health? But how about checking for it?
Or you can set the bar to full when the player respawns
Player’s character gets cloned again after dying. So this may be why it is not changed. Maybe try something inside the server script that will get the abilities and multiply the value with them.
game:GetService("Players").PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local strength = "" -- Define the location
local agility = "" -- Define the location
local vitality = "" -- Define the location
local strength = "" -- Define the location
humanoid.MaxHealth = 100 + (vitality.Value * 15) -- Example
humanoid.Health = humanoid.MaxHealth
end)
end)
Simply create a datastore saved IntValue called “MaxHealth”
Then when you upgrade the player MaxHealth, you change the IntValue and not the Character humanoid MaxHealth
To avoid to create much infinity loop scripts, there is a default script added by roblox called “Health” it is auto created in your character if there is no other script already called “Health”
So enter in play mode, copy this health script in your character, disable the play mode and past the script in the “StarterCharacterScripts”.
Here is the default code
-- Gradually regenerates the Humanoid's Health over time.
local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.
--------------------------------------------------------------------------------
local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'
--------------------------------------------------------------------------------
while true do
while Humanoid.Health < Humanoid.MaxHealth do
local dt = wait(REGEN_STEP)
local dh = dt*REGEN_RATE*Humanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
Humanoid.HealthChanged:Wait()
end
Here is how you can edit it
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Player = game.Players:FindFirstChild(Character.Name)
local MaxHealth = Player:FindFirstChild("MaxHealth")
local REGEN_RATE = 1/100 -- 0/100 if you want to disable auto heal
local REGEN_STEP = 1
while true do
while Humanoid.Health < Humanoid.MaxHealth do
local dt = wait(REGEN_STEP)
local dh = dt*REGEN_RATE*Humanoid.MaxHealth
Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
end
if MaxHealth ~= nil and not Humanoid.MaxHealth == MaxHealth.Value then
Humanoid.MaxHealth = MaxHealth.Value
end
Humanoid.HealthChanged:Wait()
end
I assume you already have a datastore set up for the health, all you really need to do is this
game:GetService("Players").PlayerAdded:Connect(function(Player)
local HealthDataStore = -- Whatever the object of your maxhealth data store is in
Player.CharacterAdded:Connect(function(Character)
Character.Humanoid.MaxHealth = HealthDataStore.Value
Character.Humanoid.Health = HealthDataStore.Value
end)
end)