MiniGames don't work

hi, I’m making a MiniGames game, all work but at the part of the game, all the rounds are only 0 seconds IDK why It don’t error anything and all works fine. My script:


local MiniGames = game.ReplicatedStorage.Minigames
local Text = game.ReplicatedStorage.Mains.Text
local MinPlayers = 2
local LobbyTime = 15

local MapData = {
['LavaRun'] = {'OneTeam',150,'Spawns',50,function()
		for _,Character in ipairs(workspace.InGame:GetChildren()) do
		   local hum = Character:FindFirstChild('Humanoid')
			if hum then
			   hum.WalkSpeed = 50
			end
		end
	end}
}

while wait() do
	if #game.Players:GetPlayers() >= MinPlayers then
		
		local GameEnded = true
		
		for i = LobbyTime,1,-1 do
			if i >= 1 then
			wait(1)
			Text.Value = 'Game Starts in '..tostring(i)
			else	
				break
			end
		end
	    
		local m = math.random(1,#MiniGames:GetChildren())
		
		local ChosenMap = MiniGames:GetChildren()[m].Name
		
		local Team1,Team2 = nil,nil
			local Main
		  for Name,Table in next,MapData do
			if Name == ChosenMap then
				Main = Table
			end
		end
		
			for _,Player in ipairs(game.Players:GetChildren()) do
					if not Player.AFK.Value == true then
						Player.Character.Parent = workspace.InGame
					end
				end
		
		     wait(0.1)
			local Teams = Main[1]
			local Time = Main[2]
		    local MoneyReward
		    local Event
			
			if Teams == 'OneTeam' then
				 Team1 = Main[3]      
			     Event = Main[5]
			     MoneyReward = Main[4]
			elseif Teams == 'TwoTeams' then
				Team1 = Main[3]
				Team2 = Main[4]
			    Event = Main[6]
			    MoneyReward = Main[5]
			end
		
		    wait(0.1)
		
		   Event()
		
		   MiniGames[ChosenMap]:Clone().Parent = workspace.MiniGame
		
			if Team1 ~= nil and Team2 ~= nil then
				for _, Player in ipairs(game.Players:GetPlayers()) do
					local Char = Player.Character
					Char.Parent = workspace.InGame
					local m = math.random(1,2)
					if m == 1 then
						local c = Player.Character
						if c and c.Head then
							local H = c.Head
							local m2 = math.random(1,#workspace.MiniGame[ChosenMap][Team1]:GetChildren())
							local H2 = workspace.MiniGame[ChosenMap][Team2]:GetChildren()[m2]
							H.CFrame = H2.CFrame
						end
					elseif m == 2 then
						local c = Player.Character
						if c and c.Head then
							local H = c.Head
							local m3 = math.random(1,#workspace.MiniGame[ChosenMap][Team2]:GetChildren())
							local H3 = workspace.MiniGame[ChosenMap][Team2]:GetChildren()[m3]
							H.CFrame = H3.CFrame
						end
					end
				end
		elseif Team1 ~= nil and Team2 == nil then
				for _, Player in ipairs(game.Players:GetPlayers()) do
					local Char = Player.Character
					Char.Parent = workspace.InGame
						local c = Player.Character
						if c and c.Head then
							local H = c.Head
							local m2 = math.random(1,#workspace.MiniGame[ChosenMap][Team1]:GetChildren())
							local H2 = workspace.MiniGame[ChosenMap][Team1]:GetChildren()[m2]
							H.CFrame = H2.CFrame
					end
				end
			
		        end
				
				for i = Time,1,-1 do
					if not i == Time then
					wait(1)
					Text.Value = ' Game Ends in '..tostring(i)
					else
						GameEnded = true
					end
				end
				
				if #workspace.InGame:GetChildren() == 0 then
					Text.Value = 'Nobody wins!'
			        GameEnded = true
				elseif #workspace.InGame:GetChildren() == 1 then
					GameEnded = true
			        local winner = workspace.InGame:GetChildren()[1].Name
			        local Pwinner = game.Players[winner]
			        game.ReplicatedStorage.Events.IncrementMoney:Fire(Pwinner,tonumber(MoneyReward))
					Text.Value = winner..' Has Won!'
				end
				
				repeat wait() until GameEnded == true
				
		        repeat
			    wait(1)
			    if GameEnded == true then
				for _, Character in ipairs(workspace.InGame:GetChildren()) do
					Character.Head:Destroy()
				end
		
		        workspace.MiniGame[ChosenMap]:Destroy()
				if GameEnded == true then
					  break
				   end
				end
		     until true == false
	
	else
		Text.Value = 'U need to be at least '..tostring(MinPlayers)..' Players!'
	end
end

Hello! The best way to recieve feedback is to show the part of the script that is not working, otherwise it’s difficult to navigate to the problem at hand.

1 Like

ok, the snippet i think u want:


	repeat wait() until GameEnded == true
		
			    if GameEnded == true then
				for _, Character in ipairs(workspace.InGame:GetChildren()) do
					Character.Head:Destroy()
				end
		
		        workspace.MiniGame[ChosenMap]:Destroy()

That has nothing to do with the length of a match. That just removes the players and the map when the bool is set to true

then the match and end part:


				for i = Time,1,-1 do
					if not i == Time then
					wait(1)
					Text.Value = ' Game Ends in '..tostring(i)
					else
						GameEnded = true
					end
				end
				
				if #workspace.InGame:GetChildren() == 0 then
					Text.Value = 'Nobody wins!'
			        GameEnded = true
				elseif #workspace.InGame:GetChildren() == 1 then
					GameEnded = true
			        local winner = workspace.InGame:GetChildren()[1].Name
			        local Pwinner = game.Players[winner]
			        game.ReplicatedStorage.Events.IncrementMoney:Fire(Pwinner,tonumber(MoneyReward))
					Text.Value = winner..' Has Won!'
				end
				
				repeat wait() until GameEnded == true
		
			    if GameEnded == true then
				for _, Character in ipairs(workspace.InGame:GetChildren()) do
					Character.Head:Destroy()
				end
		
		        workspace.MiniGame[ChosenMap]:Destroy()


I don’t think you understand what I was saying. I want the part of the code that is broken, not the entire code seperated into chunks.

this is the part that don’t work

i changed a bit my code



				for i = Time,1,-1 do
					if not i == 0 then
					wait(1)
					Text.Value = ' Game Ends in '..tostring(i)
					else
						GameEnded = true
					end
				end
				
				if #workspace.InGame:GetChildren() == 0 then
					Text.Value = 'Nobody wins!'
			        GameEnded = true
				elseif #workspace.InGame:GetChildren() == 1 then
					GameEnded = true
			        local winner = workspace.InGame:GetChildren()[1].Name
			        local Pwinner = game.Players[winner]
			        game.ReplicatedStorage.Events.IncrementMoney:Fire(Pwinner,tonumber(MoneyReward))
					Text.Value = winner..' Has Won!'
				end
				
				repeat wait() until GameEnded == true
				for _, Character in ipairs(workspace.InGame:GetChildren()) do
					Character.Head:Destroy()
				end
		
		        workspace.MiniGame[ChosenMap]:Destroy()

I believe you need help with the time portion of this script and I think I found your issue here.

for i = Time,1,-1 do
    if not i == Time then
	wait(1)
	Text.Value = ' Game Ends in '..tostring(i)
    else
	GameEnded = true
    end
end

I assume you are trying to check if i does not equal Time but you are using a not operator. Instead use the tilde(~). So instead of not i == Time do

 for i = Time,1,-1 do
    if i ~= Time then
	  wait(1)
	  Text.Value = ' Game Ends in '..tostring(i)
     else
	GameEnded = true
    end
end

I don’t exactly know if this is what you want but that entire loop made it so the game ended basically instantly. There may be more problems in the script though.

2 Likes