I made a tween function, and it's not working

Idk why, but this won’t run at all. Does anyone know how to do this tween correctly? I know you can use tweenservice I’m aware. I want my frame to pop out from the middle of the screen. You can’t do this with tweenservice, because it picks a side the frame tweens out from.

function tween(frame,t1,t2)
	spawn(function()
		for i = 1,t2,.1 do
			frame.Size = frame.Size + UDim2.new(0,0,i,0)
			wait()
		end
	end)
	spawn(function()
		for i = 1,t1,.1 do
			frame.Size = frame.Size + UDim2.new(i,0,0,0)
			wait()
		end
	end)
end

while wait(6) do
	local frame = script.Parent:WaitForChild("levelFrame")
	frame.Size = UDim2.new(0,0,0,0)
	tween(frame,.25,.3)
end
1 Like

I think it’s in your best interest to use TweenSize that way you don’t have to loop to change the size.

that isn’t the problem i’m currently faced with rn

There are a number of problems / areas of concern with your code, but only one real logic error. Based on the arguments you called tween with, your code will end up doing two for loops as follows:

for i = 1, .3, .1 do

and

for i = 1, .25, .1 do

Neither of these will run for any iterations because .3 and .25 are both smaller than 1, the initial value in the loop.

https://developer.roblox.com/en-us/articles/Roblox-Coding-Basics-Loops


This is an appropriate scenario to use TweenService. You can use AnchorPoint to control the point from which the Frame will get scaled. For example, if you set this to (0.5, 0.5), then any scaling you perform will take effect from the center of the Frame.

1 Like

thanks so much, this solved my problem!