Wait issue (unsolved)

Module Script:

local Chest = {}

Chest.Rotation = function(Chest, NumT)
	game.ReplicatedStorage.Sounds.Chest.extend:Play()
	for s = 0, 20, 1 do
		for _, Num in pairs(NumT) do
			local new = script.Frame:Clone()
			new.Parent = Chest.Other.UI.ChestGui[tostring(Num)]
			new.Position = UDim2.fromScale(.5, 1.5)
			game:GetService("Debris"):AddItem(new, 1.4)
			wait(.000000000000000000000000000000000000001) -- closer i get to 0 the more the Ui gets aligned (the green squares) but with no wait the whole thing just doesnt work

			for i = 0, 100, 1 do

				local a = TS:Create(new, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = UDim2.fromScale(.5, 1.5 - (i/60))})
				a:Play()
				a.Completed:Connect(function()
					Chest.Neon.Emitter.ParticleEmitter:Emit(1)
				end)
			end
		end
	end	
end



return Chest
- calling this function in a script
ChestModule.Rotation(workspace.Chest, {1, 2, 3, 4, 5})

im trying to get all the green squares aligned for my chest thing but idk how. i tried moving waits and even removing it completely but none of it works.

but its not aligned there all visibly misaligned. how can i get them aligned? any help would be cool

1 Like

The waits are needed as a minimum so that the thread yields, giving other code time to execute, which stops overloading and in turn stops a script crash.

wait can only wait up to 1/30th of a second, and is deprecated. You should use task.wait instead, which can wait up to 1/60th of a second, and does not have throttling. You can just do task.wait(). See if that resolves the issue of your squares not aligning.

1 Like

Not sure if this causes any issues but: wait() can only go as low as ~0.04 seconds. wait() is also deprecated, you should be using task.wait() instead (this can also go as low as ~0.008 seconds from what i know)

The waits also might be causing the squares to be spawned later (causing them to be misaligned). What could fix your issue is wrapping it in a coroutine, so each of the frames are created at the same time.
ex, change this:

for i, e in x do
   thing.Position = x;
end;

to:

for i, e in x do
   coroutine.wrap(function()
      thing.Position = x;
   end)();
end;

If this doesn’t help reply and I’ll try to help again :slight_smile:

1 Like

no change happened unfortunetly, and i dont think thats the issue, even though i have no clue what the issue is my self!

i may be stupid but its not even playing the green squares :pensive:

Chest.Rotation = function(Chest, NumT)
	game.ReplicatedStorage.Sounds.Chest.extend:Play()
	for s = 0, 20, 1 do
		for _, Num in pairs(NumT) do
			local new = script.Frame:Clone()
			new.Parent = Chest.Other.UI.ChestGui[tostring(Num)]
			new.Position = UDim2.fromScale(.5, 1.5)
			game:GetService("Debris"):AddItem(new, 1.4)
			
			coroutine.wrap(function()
				task.wait(.0001)

				for i = 0, 100, 1 do

					local a = TS:Create(new, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = UDim2.fromScale(.5, 1.5 - (i/60))})
					a:Play()
					a.Completed:Connect(function()
						Chest.Neon.Emitter.ParticleEmitter:Emit(1)
					end)
				end
			end)
		end
	end	
end

Why don’t you try making the texture one row of the green squares? That way you only have to animate one thing and the squares will always be aligned with each other.

I don’t think you properly implemented the change that doctorpepper126 suggested.
In his suggestion, the last line of the coroutine is end)() however you only have end).

Try replacing line 19 with end)()

1 Like

You have to call the coroutine
Right now, you have end) after creating the coroutine.
In order to run it, you have to do end)().

Feel free to ask if you have any more questions (:

1 Like

why dont you just put all the green squares in a scroll frame, removing the players ability to scroll and then with the script, scroll through it and delete frames that aren’t visible while adding new ones

1 Like

I just found about this this morning. But how would I do that?

The green squares are just temporary there supposed to be randomized images like some sort of loot box

Is the same as saying 0.001. Have you tried;

local rns=game:GetService("RunService")

rns.Stepped:Wait()    -- frame sync --vbs
rns.Heartbeat:Wait()  -- as fast as possible --tick

There is also a delay that can be set on the tween.

1 Like

Read up on the docs, all the info to do it should be there.

1 Like

well it works in studio mostly atleast. I feel like the “wait” is unreliable and stuff or idk

Chest.Rotation = function(Chest, NumT)
	game.ReplicatedStorage.Sounds.Chest.extend:Play()
	for _, Num in pairs(NumT) do
		coroutine.wrap(function()
			for i = 0, 10, 1 do
				local new = script.Frame:Clone()
				new.Parent = Chest.Other.UI.ChestGui[tostring(Num)]
				new.Position = UDim2.fromScale(.5, 1.5)
				game:GetService("Debris"):AddItem(new, 1.4)
				task.wait(.1)
				TS:Create(new.UIGradient, TweenInfo.new(.97, Enum.EasingStyle.Linear), {Offset = Vector2.new(0,1)}):Play()
				local a = TS:Create(new, TweenInfo.new(1, Enum.EasingStyle.Linear), {Position = UDim2.fromScale(.5, -.2)})
				a:Play()

				a.Completed:Connect(function()
					Chest.Neon.Emitter.ParticleEmitter:Emit(1)
				end)

				
				repeat task.wait() until new.Position.Y.Scale <= 1.4
			end
		end)()
	end
end

This may be a bit off topic but is there a way I can pause all the animations (the tweens) at like let’s say the end? That would be great cuz I don’t wanna clutter stuff up with my posts abt me being a dummy.

use a texture for 4 aligned squares