You can write your topic however you want, but you need to answer these questions:
1.I want to make a queue system like Omegle that functions and puts players together. Keep it simple and clear!
-
Skipping causes this to all fall apart, as some players are not detected, and it is Include screenshots / videos if possible!
-
I’ve tried restructuring the queue in several different ways, some got 3 players working but 4 did not work.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Server Script
local replicatedStorage = game:GetService("ReplicatedStorage")
local addToQueue = replicatedStorage.Start
local skip = replicatedStorage.Skip
local stop = replicatedStorage.Stop
local QueueStorage = require(script.Parent.QueueStorage)
local queue = {}
local skippingqueue = {}
local currentcalls = {}
local ChatEvent = replicatedStorage.Chat
ChatEvent.OnServerEvent:Connect(function(plr,msg)
ChatEvent:FireClient(currentcalls[plr],msg)
end)
addToQueue.OnServerEvent:Connect(function(plr)
--Add to queue
table.insert(queue,plr)
plr.InQueue.Value = true
local chosenCall
--Wait until there are actually enough people to conduct a call.
repeat wait() until #queue > 1
if currentcalls[plr] ~= nil then
return
end
local tempQueue = table.clone(queue)
table.remove(tempQueue,table.find(queue,plr))
--Choose a call
chosenCall = tempQueue[math.random(1,#tempQueue)]
currentcalls[plr] = chosenCall
currentcalls[chosenCall] = plr
--Send call info to both players.
if(chosenCall.Skipping.Value == true) then
--Wait for the player that is skipping to pick us up.--
return
end
addToQueue:FireClient(plr,chosenCall)
addToQueue:FireClient(chosenCall,plr)
print("Fail?")
--Remove the chatting player and the player from the queue
table.remove(queue,table.find(queue,plr))
table.remove(queue,table.find(queue,currentcalls[plr]))
print("EOF")
end)
skip.OnServerInvoke = function(plr,fire)
plr.InQueue.Value = true
plr.Skipping.Value = true
if(table.find(skippingqueue,plr) == nil) then
table.insert(skippingqueue,plr)
end
if(table.find(queue,plr) == nil) then
table.insert(queue, plr)
end
local num = table.find(queue,plr)
local tempqueue = table.clone(queue)
table.remove(tempqueue,num)
if currentcalls[plr] ~= nil then
print(#queue)
for i,v in pairs(queue) do
print(v)
end
local waited = false
if not (#queue > 1) then
waited = true
repeat wait() until #queue > 1
end
currentcalls[currentcalls[plr]] = nil
if waited then
tempqueue = table.clone(queue)
table.remove(tempqueue,table.find(queue,plr))
end
--Choose a random player from the queue
local chosenCall = tempqueue[math.random(1,#tempqueue)]
local p2 = table.find(tempqueue,chosenCall)
local prevcurrentcall = currentcalls[plr]
if currentcalls[plr] == chosenCall then
if #queue == 2 and queue[1] == plr and queue[2] == currentcalls[plr] then
repeat wait() until queue[2] ~= currentcalls[plr]
chosenCall = queue[math.random(1,#queue)]
end
end
currentcalls[plr] = chosenCall
currentcalls[chosenCall] = plr
print(chosenCall)
print(#queue)
table.remove(queue,num)
table.remove(queue,p2)
table.remove(skippingqueue, table.find(skippingqueue, plr))
if(#skippingqueue >= 1) then
for k,v in pairs(skippingqueue) do
if currentcalls[v] ~= nil then
stop:FireClient(currentcalls[v])
stop:FireClient(v)
local skipto = queue[math.random(1, #skippingqueue)]
addToQueue:FireClient(v, skipto)
--addToQueue:FireClient(skipto,v)
table.remove(skippingqueue, table.find(skippingqueue, v))
print("v: " .. v.Name)
print("chosenCall: " .. chosenCall.Name)
end
end
end
--Send them to the player
addToQueue:FireClient(chosenCall,plr)
print("addToQueue: " .. chosenCall.Name .. " PLR: " .. plr.Name)
if fire then stop:FireClient(prevcurrentcall) end
plr.Skipping.Value = false
return chosenCall
else
return nil
end
end
stop.OnServerEvent:Connect(function(plr)
Stop(plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
Stop(currentcalls[plr])
end)
game.Players.PlayerAdded:Connect(function(plr)
local InQueue = Instance.new("BoolValue")
InQueue.Name = "InQueue"
InQueue.Value = false
InQueue.Parent = plr
local Skipping = Instance.new("BoolValue")
Skipping.Name = "Skipping"
Skipping.Value = false
Skipping.Parent = plr
end)
function Stop(plr)
local index = table.find(queue, plr)
if index then
table.remove(queue, index)
if currentcalls[plr] then
stop:FireClient(currentcalls[plr])
currentcalls[plr] = nil
end
end
plr.InQueue.Value = false
end
Client Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Start = ReplicatedStorage.Start
local Stop = ReplicatedStorage.Stop
local Skip = ReplicatedStorage.Skip
local Button = script.Parent
local InQueue = game.Players.LocalPlayer.InQueue
local P2 = script.Parent.Parent.Parent.Parent.Player2
local Player2ViewportFrame = script.Parent.Parent.P2
Button.Activated:Connect(function()
if not InQueue.Value then
script.Parent.BackgroundColor3 = Color3.new(0.972549, 0.227451, 0.317647)
script.Parent.Text = "STOP"
Start:FireServer()
else
--TODO: Change the button to Green--
script.Parent.Text = "START"
Stop:FireServer()
P2.Value = ""
end
end)
Stop.OnClientEvent:Connect(function()
P2.Value = ""
Player2ViewportFrame.CurrentCamera = nil
script.Parent.Parent.NoQueue.Visible = true
if(P2.Value == nil) then
Start:FireServer()
else
P2.Value = Skip:InvokeServer(false).Name
end
Player2ViewportFrame.CurrentCamera = Player2ViewportFrame.Camera
end)
Start.OnClientEvent:Connect(function(player2)
print("start")
print(player2.Name)
if(player2 == nil) then
print("NIL")
P2.Value = player2
Player2ViewportFrame.CurrentCamera = nil
else
print("detected")
P2.Value = player2.Name
script.Parent.Parent.NoQueue.Visible = false
Player2ViewportFrame.CurrentCamera = Player2ViewportFrame.Camera
end
end)
Client Skip Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Skip = ReplicatedStorage.Skip
local Button = script.Parent
local InQueue = game.Players.LocalPlayer.InQueue
local P2 = script.Parent.Parent.Parent.Parent.Player2
Button.Activated:Connect(function()
if InQueue == false then
--TODO: Turn the button red or something
return
else
local p2 = Skip:InvokeServer(true)
P2.Value = p2.Name
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.