how can I adjust this script for it to work properly? Btw I'm a beginner, I would appreciate your help!
local MaxHealth = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid local Health = script.Parent.Health local Bar = script.Parent Health.Changed:connect(function() Bar.Size = TweenSize(UDim2.new(Health.Value/MaxHealth.MaxHealth,0,1,0)) ----- problem here! if Health.Value > MaxHealth.MaxHealth then Health.Value = MaxHealth.MaxHealth elseif Health.Value < 1 then Health.Value = 0 end end)
Your Code :
local MaxHealth = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid local Health = script.Parent.Health local Bar = script.Parent Health.Changed:connect(function() Bar.Size = TweenSize(UDim2.new(Health.Value/MaxHealth.MaxHealth,0,1,0)) ----- problem here! if Health.Value > MaxHealth.MaxHealth then Health.Value = MaxHealth.MaxHealth elseif Health.Value < 1 then Health.Value = 0 end end)
Code fix :
local MaxHealth = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid local Health = script.Parent.Health local Bar = script.Parent Health.Changed:connect(function() Bar:TweenSize(UDim2.new(Health.Value/MaxHealth, "Out", "Quad", 1, false, nil) if Health.Value > MaxHealth.MaxHealth then Health.Value = MaxHealth.MaxHealth elseif Health.Value < 1 then Health.Value = 0 end end)
I'll explain your line of TweenSize here :
UDim2
is a Data Type composed of two UDims, one for the X coordinate and one for the Y coordinate, used to position and size GUIs. Link for explain UDim2 : HERE
Out
is the EasingDirection and EasingDirection
Enum Sets the direction for tweening.
You can use : In
, Out
or InOut
. For this i recommend you to use : Out
. Link for explain EasingDirection : HERE
Quad
is the EasingStyle and EasingStyle
Enum determines the way in which tweening will act.
You can use : Linear
, Sine
, Back
, Quad
, Quart
, Quint
, Bounce
or Elastic
. For this i recommend you to use : Quad
. Link for explain EasingStyle : HERE
1
is how it will take time (float time) for Change the Size
of the frame or the position if you use TweenPosition
. here is 1 for 1 second. Link for explain float time : didn't found one.
false
is the bool override. Link for explain override : didn't found one.
nil
is the Function callback. Link for explain callback : HERE
For more information about TweenSize go : HERE
Sorry for my bad grammar ^-^