So, it works once. Selects a single map, just fine. But then it selects multiple maps. Idk why, and I need help. Please help.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)	
local HRP = char.HumanoidRootPart		
local GMS = game.ReplicatedStorage.GameModes:GetChildren()
local SwordMaps = GMS.SwordFightMaps
local FloodMaps = GMS.FloodEscapeMaps
local ITime = script.IntermissionTime
local GTime = script.GameTime
local GCTime = script.GameCoutdown
local Message = Instance.new("Hint", game.ReplicatedStorage)
local players = game.Players:GetPlayers()
local currentmap = false		
		
local findWinner = function(plr)
			local DeadPlayers = {}
			local PossibleWinners = {}
			
			for i,v in pairs(players) do
				if v.Dead.Value == true then
					table.insert(DeadPlayers, v)
				elseif v.Dead.Value == false then
					table.insert(PossibleWinners, v)
				end
				for i,v in pairs(PossibleWinners) do
					print(#PossibleWinners)
					if #PossibleWinners == 1 then
						v:WaitForChild("leaderstats").Wins.Value = v.leaderstats.Wins.Value + 1
						v:WaitForChild("leaderstats").Cash.Value = v.leaderstats.Cash.Value + 100
			end
		end
	end
end
		
while true do
	
		local ChosenGameMode = GMS[math.random(1,#GMS)]
			
			print(ChosenGameMode.Name)
			
		local CGM = ChosenGameMode:GetChildren()
		local ChosenMap = ChosenGameMode[math.random(1,#CGM)]
		local MapClone = ChosenMap:Clone()
		print(MapClone.Name)
			
		wait(ITime.Value)
			
		Message.Parent = workspace
		Message.Text = "Gamemode chosen: "..ChosenGameMode.Name.."."
		wait(5)
		Message.Parent = game.ReplicatedStorage
			
		MapClone.Parent = game.Workspace
		local TpPart = MapClone:FindFirstChild("TpPart")
		HRP.Position = TpPart.Position
		wait(GCTime.Value)
			
		if ChosenGameMode.Name == "SwordFighting" then
			local sword = game.ReplicatedStorage.Sword
			for i,v in pairs(players) do
				local SC = sword:Clone()
				SC.Parent = v.Backpack	
				print(v.Name)
				wait()					
			end

			
			wait(GTime.Value)
			findWinner()
			MapClone:Destroy()	
			plr:LoadCharacter()		
			plr.Dead.Value = false
			end	
		end
	end)
end)

2 comments

0

Try adding wait() for while true do loop

0

I'd like to add, it also picks a gamemode twice after the first loop.