I'm trying to do a switch thingy for a game. Basically how it works is that I have 2 squares on the sides and 1 bigger than the other 2 in the middle. Then there is 2 buttons, "<" and ">". Clicking < will tween the right square to middle, middle to left and left will just teleport tothe right side. Clicking the other will do this in reverse.
The BKG is a frame that is parent of the script. The frames, left, middle and right, are in the BKG and the buttons are in there too. |StarterGui| {|BKG| {|Frame 1| <- left |Frame 2| <- middle |Frame3| <- right |Script| <- this script |Next| <- ">"-button |Prev| <- "<"-button
local BKG = script.Parent
local t =
{
BKG["Frame 1"],
BKG["Frame 2"],
BKG["Frame 3"]
}
local n,p = BKG.Next, BKG.Prev
local stats =
{
{position = UDim2.new(0, 10,0, 40), size = UDim2.new(0, 20,0, 20)},
{position = UDim2.new(0, 35,0, 35), size = UDim2.new(0, 30,0, 30)},
{position = UDim2.new(0, 70,0, 40), size = UDim2.new(0, 20,0, 20)}
}
local done =
{
false,
false,
false
}
function tween_right()
for i,f in pairs(t) do
local new = i + 1
local tween
if new > 3 then
new = 1
tween = false
else
tween = true
end
if tween then
t[i]:TweenSizeAndPosition(stats[new].size,stats[new].position)
spawn(function()
while t[i].Size ~= stats[new].size and t[i].Position ~= stats[new].position do
wait()
end
done[i] = true
end)
else
t[i].Size = stats[new].size
t[i].Position = stats[new].position
done[i] = true
end
end
while not (done[1] and done[2] and done[3]) do
wait()
end
for i,f in pairs(t) do
local new = i + 1
if new > 3 then
new = 1
end
t[new] = f
end
end
n.MouseButton1Click:connect(tween_right)
if you would find the solution to this problem, I would really appreciate it
Thanks,
SwaggyDuckie

1 comment
Instead of spam checking that the size and position are equal to something, just wait one second, because that's how long it takes.