I am trying to tween the health bar but it’s tweening incorrectly and re-sizing it wrong once the character has been damaged and when they begin to heal it’s not correct.
Here is the script;
local Player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")
local MainGUI = script.Parent.Parent.Parent
local MainFrame = MainGUI.HealthAndEnergy
local HealthLine = MainFrame.Health
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Time = 1
local Information = TweenInfo.new(Time, Enum.EasingStyle.Quad)
local function OnHealthChanged()
local NewHealth = math.floor(Humanoid.Health)
local Goal = {}
Goal.Size = UDim2.fromScale(NewHealth / 300, 0.6)
local Tween = TweenService:Create(HealthLine, Information, Goal)
Tween:Play()
end
Humanoid:GetPropertyChangedSignal("Health"):Connect(OnHealthChanged)
This fixed the size issue but it didn’t fix the issue completely.
When I take damage the bar goes back right but it doesn’t go back to it’s normal size. The normal size of the ImageLabel is {0, 342},{0, 6} and when the character is damaged and begins to regenerate it is supposed to go back to that size.
local Player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")
local MainGUI = script.Parent.Parent.Parent
local MainFrame = MainGUI.HealthAndEnergy
local HealthLine = MainFrame.Health
local DuplicateHealthLine = HealthLine.Bar
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Time = 1
local Information = TweenInfo.new(Time, Enum.EasingStyle.Linear)
local function OnHealthChanged()
local NewHealth = math.floor(Humanoid.Health)
local MaxHealth = Humanoid.MaxHealth
local Goal = {}
Goal.Size = UDim2.new(NewHealth / MaxHealth, 0, HealthLine.Size.Y.Scale, HealthLine.Size.Y.Offset)
local Tween = TweenService:Create(DuplicateHealthLine, Information, Goal)
Tween:Play()
end
Humanoid:GetPropertyChangedSignal("Health"):Connect(OnHealthChanged)