Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to smooth out a 'progress bar'?

Hi there. I am trying to make a game similar to that of Mining Simulator as a school project. I've gotten some features down, but I am stuck on this one.

progress.Size = UDim2.new((cursorObject.Parent:FindFirstChild("Progress").Value/cursorObject.Parent:FindFirstChild("MaxHealth").Value),0,1,0)

The one above updates the GUI anytime the progress value changes.

cursorObject.Parent.Progress.Value = cursorObject.Parent.Progress.Value + damage
wait(1)

The one above is basically what is changing the value of the progress, constantly activating in a while loop, while mousebutton1 is being pressed.

Every time the GUI updates to match the progress value, it jumps to that value. This is expected. I am just wondering how would I smooth the transition out? Thank you.

3 comments

1

You can use :TweenSize() to specify a customary transition type between the current position an the given UDim2

0

If by smooth do you mean nicer/prettyer?

0

Yea. By smoothing out I mean making it look appealing to the eye. Feahren, could you elaborate? Thank you!

1 answer

✓ Accepted answer

If you mean nicer/prettyer, you should use :Tweensize(). Here is a example the roblox wiki includes. It is a useful template to use so it should make it a bit easyer to change the settings.

local guiObject = script.Parent
local willTween = guiObject:TweenSize(
	UDim2.new(0.5, 0, 0.5, 0),  -- endSize (required)
	Enum.EasingDirection.In,    -- easingDirection (default Out)
	Enum.EasingStyle.Sine,      -- easingStyle (default Quad)
	2,                          -- time (default: 1)
	true,                       -- should this tween override ones in-progress? (default: false)
	callback                    -- a function to call when the tween completes (default: nil)
)
 
if willTween then
	print("The GuiObject will tween") 
else
	print("The GuiObject will not tween")
end

If this helped you be sure to Accpet the answer so we both get rep!

2 comments

0

Wow. Thank you so much! It worked! I basically replaced the UDim2.new in the code you provided, with the one I provided. The animation works! I just need to make it quicker. Thanks to the both of you for helping me! Cheers!

0

Your welcome.

This discussion is preserved as it was. New answers, comments, and votes are closed.