This script Is supposed to choose a random minigame from a Model with models inside. And then teleport the players on one of the spawns on that following model.

Then teleport all the players and start a hint 50-second timer after it hits 0 it plays a whistle sound called "EndMatchSound" and then teleports them back to the lobby.

1 person needs to be in the game for it to start.

Minigames are in lighting, (Grinch Parkour and Platform Run)

"Spawn" Minigame spawns "LobbySpawn" The lobby spawn

EndMatchSound: Sound playing on the whole server when the timer hits 0

MainScript / Normal script in workspace

timee = 4
time2 = 50

minigames = game.Lighting.Minigames:GetChildren()

h = Instance.new("Hint", game.Workspace)


while true do

if game.Players.NumPlayers == 1 then
	h.Text = "Loading game..."
	wait(3)
	ranGame = math.random(1, #minigames)
	gameChosen = minigames[ranGame]
	h.Text = "Minigame chosen: " .. gameChosen.Name
	wait(3)
	h.Text = "Minigame Length: 50 sec"
	wait(3)
	gameChosenClone = gameChosen:Clone()
	gameChosenClone.Parent = game.Workspace
		wait(3)
		timee = 4
		time2 = 50
	--Teleporting people to map
	spawns = gameChosenClone.Spawns:GetChildren()
		for i,v in pairs(game.Players:GetPlayers()) do
			name = v.Name
			check = game.Workspace:FindFirstChild(name)
			if check then
				checkHumanoid = check:FindFirstChild("Humanoid")
				if checkHumanoid then
					check:MoveTo(spawns[i].Position)
				end
			end
		end
		for i = 0,3,1 do
			timee = timee-1
			h.Text = "Game begins in: " .. timee
			wait(1)
		end
	--Countdown until the game ends
	for i = 1,50 do
		time2 = time2-1
		if i == 1 then
			player = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
		end
		----------------------------------------------------------
		if i == 50 then
				lobbyspawn = game.Workspace.LobbySpawn
		for i,v in pairs(game.Players:GetPlayers()) do
			name = v.Name
			check = game.Workspace:FindFirstChild(name)
			if check then
				checkHumanoid = check:FindFirstChild("Humanoid")
				if checkHumanoid then
					wait(0.5)
					check:MoveTo(lobbyspawn.Position)
					wait(3)
					math.random(1,5)
				end
			end
		end
		-----------------------------------------------------------
			
			
		end
		h.Text = "Time left: " .. time2
		    wait(1)	
	
			if i == 50 then
				game.Workspace.EndMatchSound:Play()
		h.Text = "Game ended!"
		wait(3)
		gameChosenClone:Destroy()
		
			end
			end
   else	
	    h.Text = "There needs to be at least 1 player for the game to start!"
   end
   wait(1)

end

Would really appreciate it if someone could help me out. I'm going to play this with my viewers on one of my twitch streams sometimes.

3 comments

0

Okay but what's the problem?

0

don't store stuff in Lighting that's what ReplicatedStorage is for

0

Also you may want to take a look at that first if statement in the while loop. I assume you'd want the game to still start if there were 2 players? >=