I’m using an IntValue to increase a GUI that converts the whole number into a percentage and changes the GUI’s size. I have completed that and it works perfectly. My next task was to create a drainage where it slowly takes away a specific value from the IntValue until it reaches zero. I attempted to do this with a while loop which ended up doing nothing. I combined it with the Changed event and it ended up changing it but it would double the decreased value after each run through. Under is the current code I have that does not work.
while scalingnumber.Value > 0 do
wait(1)
scalingnumber.Value = math.max(scalingnumber.Value - 5, 0)
end
the code is ran inside of the GUI im changing within the local script that changes it arleady.
reason i didnt do what you provided is because when i attempted to get it to work, it would double and end up going into the negatives causing the gui to go backwards when it reaches 0. the code is after the function inside a script that is called once. The script below is the entire script inside of the local script that changes the size of the GUI based on the number inputed within the IntValue. Im aware this may not be the most efficient way either.
local gui = game.Players.LocalPlayer.PlayerGui.FeverBar.FeverContainer.Background.FeverBar
local scalingnumber = script.FeverAmount
local function valuechanged()
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local percent = scalingnumber.Value / 100
local goal = {}
goal.Size = UDim2.new(1,0,percent,0)
local tween = tweenservice:Create(gui, tweeninfo, goal)
tween:Play()
end
while scalingnumber.Value > 0 do
wait(1)
scalingnumber.Value = math.max(scalingnumber.Value - 5, 0)
end
scalingnumber.Changed:Connect(valuechanged)
local gui = game.Players.LocalPlayer.PlayerGui.FeverBar.FeverContainer.Background.FeverBar
local scalingnumber = script.FeverAmount
local function valuechanged()
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.5,Enum.EasingStyle.Linear)
local percent = scalingnumber.Value / 100
local goal = {}
goal.Size = UDim2.new(1,0,percent,0)
local tween = tweenservice:Create(gui, tweeninfo, goal)
tween:Play()
end
scalingnumber.Changed:Connect(valuechanged)
while scalingnumber.Value >= 0 do
task.wait(1)
scalingnumber.Value = math.max(scalingnumber.Value - 5, 0)
print("decreased by 5")
end