To give you some context of my game is that I have a main script that does most of the code in it and local scripts awaiting to be activated by RemoteEvents. One thing I ran into is the fact that I need one of my local script needs to be running for about 5+ seconds while the main script needs to wait for it to be finished. Once the local script is finished, the main script continues to move on. At first, I was thinking running the code like this:
Main Script:
--Code...
--Code...
--More Code...
local rep = game:GetService("ReplicatedStorage")
rep.RemoteEvent1:FireAllClients()
repeat wait() until rep.RemoteEvent2:OnServerEvent:Connect(function()
--Continue with code
end)
Local Script:
local rep = game:GetService("ReplicatedStorage")
rep.RemoteEvent1.OnClientEvent:Connect(function()
--Code
rep.RemoteEvent2.FireServer()
end)
This way I am able to wait for the local script to be finished so that the main script could run again. It seemed like a sure proof plan to me but after I tried it, it skipped over it and did not wait for the local script to finish! What should I do?

2 comments
?
Repeat until loops repeat code until a certain condition is met. OnServerEvent:Connect() returns an RBXScriptConnection, which will immediately break the loop, as ANY value that is not nil or false is considered truthy in boolean context. So remove the repeat loop.