When the Wait method is used with OnServerEvent or OnClientEvent, it throws the following error for each queued event:
cannot resume non-suspended coroutine
The following scripts demonstrate this behavior:
-- Script; game.ServerScriptService
local remote = Instance.new("RemoteEvent")
remote.Parent = game.ReplicatedStorage
game.Players.PlayerAdded:Connect(function(player)
-- Immediately send messages.
for i = 1,3 do
print("SEND",player,i)
remote:FireClient(player,i)
end
wait(1)
-- Tell client to start receiving messages.
local sync = Instance.new("BoolValue")
sync.Name = "Sync"
sync.Parent = game.ReplicatedStorage
end)
-- LocalScript; game.ReplicatedFirst
-- Wait until server says to start receiving messages.
local sync = game.ReplicatedStorage:WaitForChild("Sync")
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
-- Use Wait to receive a message. Server sent 3 messages, so there are 3 queued up.
print("RECEIVE",remote.OnClientEvent:Wait())
-- expected:
-- RECEIVE 1
-- result:
-- cannot resume non-suspended coroutine
-- cannot resume non-suspended coroutine
-- cannot resume non-suspended coroutine
Reproduction:
RemoteEventWaitError.rbxl (13.6 KB)