This is how the problem is happening. When i touch the part it runs this function multiple times. And I have a problem with the "inQueue" variable. I know that it is setting iot back to false and that is the problem but i do not know where to set it to true and false.
Here is my code. (THE PROBLEM IS HAPPENING BETWEEN LINES 7-17:
local Table = {}
local MaxPlayers = 2
local ts = game:GetService("TeleportService")
game.Workspace.Pad1.CanTouch = true
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"
script.Parent.Touched:Connect(function(TouchedPart)
if TouchedPart.Parent:FindFirstChild("Humanoid") and #Table < 2 then
local inQueue = false
if not inQueue then
inQueue = true
local Character = TouchedPart.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
table.insert(Table,Player)
print(#Table)
print(#Table)
print(script.Parent.CanTouch)
print(inQueue)
if #Table < 2 then
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 1/2"
repeat
wait(0.01)
until #Table > 1
else
if #Table > 1 then
game.Workspace.TwoPlayerPlayers.Value = 1
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 2/2"
wait(2)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 10"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 9"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 8"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 7"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 6"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 5"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 4"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 3"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 2"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 1"
wait(1)
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING NOW"
wait(2)
game.Workspace.TwoPlayerPlayers.Value = 0
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"
Table = {}
end
end
end
end
end)

1 comment
JESUS CHRIST THANK YOU YOU ARE A HERO