Hi, I am trying to make a progress bar where if it achieves a size x, it needs to execute a command.
The problem is that the progress bar moves a bit outside of the desired location and I can’t seem to be able to execute when it achieves x size.
Any ideas?
local smallerNumber = 0
local biggerNumber = 100
for i = smallerNumber, biggerNumber, 0.5 do
wait(0.1)
script.Parent.Bar.Size = UDim2.new(i/biggerNumber, 0, 0.8, 0)
end
You may want to constrain i/biggerNumber between 0 and 1. You can do this with math.clamp(). This will always ensure that i/biggerNumber is between 0 and 1. If it exceeds 1 or deceeds 0, it’d be constrained back to 1 and 0.
for i = smallerNumber, biggerNumber, 0.5 do
task.wait(0.1)
script.Parent.Bar.Size = UDim2.new(math.clamp(i/biggerNumber, 0, 1), 0, 0.8, 0)
end
If that’s not an issue, then you should revise how you listen for changes to Size.X.Scale.