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

How would i make this frame smoothly deplete along with the text?

UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
	local KeyCode = Input.KeyCode
	if not gameProcessedEvent then
		
		if KeyCode == Enum.KeyCode.T and active == false then
			active = true
			print("test")
			Event:FireServer(active)
			while active == true do
				wait(0.1)
				charge = charge + 1
				print(charge)
				Ki.KiGui.Frame.Size = Ki.KiGui.Frame.Size - Ki.KiGui.Frame:TweenSize(UDim2.new(0, 1, 0, 0), "Out", "Linear", 1, true) 
				Ki.KiGui.Frame.Ki.Text = Ki.KiGui.Frame.Ki.Text - 1
			end
		end
	end
end)

When tested, the whole frame just gets smaller and gets out of position. I was wondering how to make it so the bar drains towards the left along with the number

1 answer

✓ Accepted answer

That's an interesting topic, I love smooth, organic HUDs too!

[ I ] . Are all variables correctly defined?

[ II ] . On Line 13, TweenSize() already handles the size for you, so you don't have to subtract anything from Size. Also, TweenSize() only tweens if you execute it on the object itself, not as a part of an arithmetic operation. This is much better.

Ki.KiGui.Frame:TweenSize(UDim2.new(0, Ki.KiGui.Frame.Size.X.Offset - 1, 0, Ki.KiGui.Frame.Size.Y.Offset), "Out", "Linear", 1, true)
-- You can replace 'Ki.KiGui.Frame.Size.X.Offset' and 'Ki.KiGui.Frame.Size.Y.Offset' with a reference to that same property if you want
-- I'm guessing you used just Offset and left Scale to 0. If not, replace the Scale values with the correct ones

Your frame moved out of position because you were setting its Y-axis size property to (0, 0) instead of keeping it to its original value (unless Y was already (0, 0)).

[ III ] . You can't subtract a number from a string, that's why Line 14 gives you an error for doing so. Instead, create a local variable with the number you want to display, and pass that value to the Text property of the object. Remember, it has to be either a TextLabel, TextButton or TextBox for it to have said property. This fixes it.

local number = X   -- Replace X with your initial value, or the reference to where it should get its value from
Ki.KiGui..Frame.Ki.Text = number

Hope that helps!

~TheArmoredReaper

3 comments

0

Ohh, i sorta understand what you're saying. But when i replaced my line with yours, nothing happens. Am i suppose to subtract if from something? Sorry i'm not use to UDim2

0

To tween it, you should set the UDim2 values to the same as the current size of the frame, and subtract a number from it, but inside the arguments, not outside as you had done

0

Ohh, alright thanks

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