I am making a card game, and I’m currently trying to set up matchmaking.
There’s a table with 4 chairs, and when 2 or more people sit at it, a timer (BillboardGUI) above the table becomes visible and starts counting down from 30 seconds.
If a player leaves the table during the countdown and the amount of players is now less than 2, the countdown stops (and the gui becomes invisible)
When the 30 seconds end, the game begins. Suppose it’d be the function: StartGame() .
I thought of using Coroutines for the timer, which seems the right thing to do, but I had problems with it such as not being able to close it.
The following script sets up 4 events that fire when the occupant of a chair changes. If there’s no occupant, that means a player has left the table, and it subtracts 1 from the playerCount. If there is a player, it adds 1 to the playerCount.
I don’t know how to continue the script from this
local function MatchMaking()
local playerCount = 0
local TimerText = script.Parent.BillboardGui.Timer
TimerText.Visible = false
for i = 1, 4 do -- Set up "Check Chair" functions
local Chair = script.Parent["Chair"..tostring(i)].Seat
Chair:GetPropertyChangedSignal("Occupant"):Connect(function()
if Chair.Occupant == nil then
playerCount -= 1
else
playerCount += 1
end
print(playerCount)
end)
end
end
MatchMaking()
How it’s set up: (each chair is exactly the same except for the name)