Musical Chairs Game

I am trying to create a Musical chairs game but I dont know how would I detect after a certain amount of time if a player on the Playing Team is siting or not. I have been at this for quite a few hours now and I just have no clue.

I will post the code I am using for my round system at the moment, the code teleports the player and switches the players team when the game starts and after the game all players are switched back to the Lobby team and are teleported. Again I have on clue how to detect if the Player on the playing team is sitting or not. Please help, thanks.

And yes I have tried searching on Dev Hub for some solutions/answers but I have had no luck.

local intermissionLength = 35
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local InGame = game.ReplicatedStorage.InGame
local GameLength = 8
local WaitLength = math.random(5, 15)
local roundLength = GameLength + GameLength + WaitLength + WaitLength

local function gameTimer()
	while wait() do
		if InRound.Value == false then
			wait()
			coroutine.yield()
		end
		if InRound.Value == true then
			for i = WaitLength, 1, -1 do
				InGame.Value = false
				wait(1)
				print("Waiting: ".. i .. "")
			end
			for i = GameLength, 1, -1 do
				InGame.Value = true
				wait(1)
				print("InProgress: ".. i .. "")
			end
		end
	end
end

InGame.Changed:Connect(function()
	if InGame.Value == false then
	game.Workspace:FindFirstChild("ChairsIslandSpot1"):FindFirstChild("Border").CanCollide = true
	elseif InGame.Value == true then
	game.Workspace:FindFirstChild("ChairsIslandSpot1"):FindFirstChild("Border").CanCollide = false
	end
end)

InGame.Changed:Connect(function()
	if InGame.Value == false then
		for _, player in ipairs(game.Players:GetPlayers()) do
			if player.Team == game.Teams["Playing"] then
				player:LoadCharacter();
				local playersOnTeam = game:GetService("Teams")["Playing"]:GetPlayers()
				local numberPlayersOnTeam = #playersOnTeam
				print(numberPlayersOnTeam)
				if numberPlayersOnTeam == 1 then
					print("1 player")
				elseif numberPlayersOnTeam == 2 then
					print("2 players")
				end
			end
		end
	end
end)


InRound.Changed:Connect(function()
	if InRound.Value == true then
		for i,v in pairs(game.Players:GetChildren()) do
			if v.Team == game.Teams["Lobby"] then
				v.Team = game.Teams["Playing"]
				for _, player in ipairs(game.Players:GetPlayers()) do
					if player.Team == game.Teams["Playing"] then
						player:LoadCharacter();
						local playersOnTeam = game:GetService("Teams")["Playing"]:GetPlayers()
						local numberPlayersOnTeam = #playersOnTeam
						print(numberPlayersOnTeam)
						spawn(gameTimer)
						yielded = false
					end
				end
			end
		end
	else
		for i,v in pairs(game.Players:GetChildren()) do
			if v.Team == game.Teams["Playing"] then
				v.Team = game.Teams["Lobby"]
				for _, player in ipairs(game.Players:GetPlayers()) do
					if player.Team == game.Teams["Lobby"] then
						player:LoadCharacter();
						spawn(gameTimer)
					end
				end
			end
		end
	end
end)

local function roundTimer()
	while wait() do
		for i = intermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .. ""
		end
		for i = roundLength, 1, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game in progress"
		end
	end
end

spawn(roundTimer)

Any help is appreciated

Hello, i think by just recall the timer it might work (example is below). Just add this at the whole bottom of your code but just above the spawn(roundTimer) line. Please let me know if this works!!

while wait(10) do -- change 10 to each time you want to check it
	local theplayingteam = game:GetService("Teams")["Playing"]:GetPlayers()
	local theplayingteamcount = #theplayingteam
	
	if theplayingteamcount == 0 then
		spawn(roundTimer)
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.