Maybe try filling in all the parameters: health:TweenSize(UDim2.new(currentHealth / maxHealth, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Bounce, 0.5, true)
I don’t think much will change, but it’s always good to try. If it doesn’t work, I recommend moving the health bar on the client instead. Check the bar size on the server first, if the size is different than the client’s bar then the problem is that you’re doing it on the server.
I also recommend updating the humanoid’s maxhealth everytime the health changes
(maxHealth = humanoid.MaxHealth at each HealthChanged event).
local serverStorage = game.ServerStorage
local healthBar = serverStorage.HealthBar
local health = healthBar.Health
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local healthBarClone = healthBar:Clone()
healthBarClone.Parent = character:WaitForChild("Head")
local health = healthBarClone.Health
local humanoid = character.Humanoid
local maxHealth = humanoid.MaxHealth
humanoid.HealthChanged:Connect(function(currentHealth)
health:TweenSize(UDim2.new(currentHealth / maxHealth, 0, 1, 0), "In", "Bounce")
end)
end)
end)
local serverStorage = game.ServerStorage
local healthBar = serverStorage.HealthBar
local health = healthBar.Health
function AddHealth(character)
local healthBarClone = healthBar:Clone()
healthBarClone.Parent = character:WaitForChild("Head")
local humanoid = character.Humanoid
local maxHealth = humanoid.MaxHealth
humanoid.HealthChanged:Connect(function(currentHealth)
health:TweenSize(UDim2.new(currentHealth / maxHealth, 0, 1, 0), "In", "Bounce")
end)
end
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
AddHealth(character)
player.CharacterAdded:Connect(AddHealth)
end)
The character may not have loaded yet, which is why it is not working.