Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you prevent 'Remote Event Queue Exhausted'? (Or what alternatives for 'while true do'?)

Asked by 5 years ago
Edited 5 years ago

! Server Script in Workspace

   audioparts = workspace.AudioParts
local clonemusicEvent = game:GetService("ReplicatedStorage"):WaitForChild("HubTownMusic")
locations = {}
while true do wait() --print('waiting for player..')
for i, v in pairs(game.Players:GetChildren()) do
if v.Character ~= nil then print('found character')
if v.Character:FindFirstChild("UpperTorso") ~= nil then
repeat wait(.1) until (Vector3.new(audioparts.HubTownArea.Position) - v.Character.HumanoidRootPart.Position).magnitude <= 750
clonemusicEvent:FireClient(v)
end
--print('fired client')
end
end
end

Creating an audio system that will detect if the player has the Audio GUI or not. Here is also the local script for context.

    repeat wait() until game.Players.LocalPlayer.Character ~= nil

local Players = game:GetService("Players")



local Gui = game.Workspace.AudioParts.HubTownArea.Audio

local cloneguievent = game:GetService("ReplicatedStorage"):WaitForChild("HubTownMusic")

local Event = game.ReplicatedStorage.HubTownMusic



Event.OnClientEvent:connect(function() wait()

if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Audio") then

--print("Has gui")

else

--print("No gui")

local Clone = Gui:Clone()

Clone.Parent = game.Players.LocalPlayer.PlayerGui

end

end)

I understand that the loop spams the event and in that case can't work properly (or at all), so i'm asking for an alternative for the 'while true do' loop. Maybe Renderstepped would work? But how would I implement that efficiently? Anyone got any ideas or easy solutions (or complicated if need be.)

EDIT: The picture and the event being fired do not match up, but that is because there are multiple versions of the script with the only difference being a different GUI and event name. All versions still get exhausted and do not work.

0
Don't use :connect() it's deprecated. Use :Connect(). namespace25 594 — 5y
0
Are you saying that would be a fix? UnderWorldOnline 59 — 5y
0
^ That’s just a suggestion. I recommend you use the PlayerAdded and CharacterAdded event together instead of looping. Spam firing the remote event can give you that error, and RenderStepped just makes that even worse. :P User#20279 0 — 5y

Answer this question