So my stamina bar goes outside the frame when it shouldn’t. I want the bar to stay inside the frame even when the Max Value increases. Here’s the script I’m using and a video of the problem happening, any help is appreciated! https://gyazo.com/9af2b48d54ce47b1174e14fd3666122a
here in the video the stamina value is decreasing by 10 out of 100 and the X scale of the bar is 0.90, the bar is only inside the frame when the X scale is 0.50 I hope this helps some.
local Player = game.Players.LocalPlayer
local Stamina = Player:WaitForChild("Stamina")
local MaxStamina = Player:WaitForChild("MaxStamina")
Player.Character:WaitForChild("Humanoid").Died:Connect(function()
Stamina.Value = MaxStamina.Value
end)
local function refresh()--Function refresh
if Stamina.Value < MaxStamina.Value then
local tweenamount = math.clamp(Stamina.Value,0, MaxStamina.Value)
script.Parent:TweenSize(UDim2.new((1/MaxStamina.Value) * tweenamount,0,0.1,0),Enum.EasingDirection.In, "Linear",0.1)
end
end
Stamina.Changed:Connect(function()
refresh()
if Stamina.Value > MaxStamina.Value then
Stamina.Value = MaxStamina.Value
end
end)
MaxStamina.Changed:Connect(function()
refresh()
end)