Problems with implementing a double trouble game-mode

I’ma just get straight to the point and tell the issues

Issues with just 2 players in game:

  • Both players are sometimes Baldi and student at the same time

  • sometimes both players are student instead of one Baldi and one student

  • aometimes both players are baldi however one of them are given the student tags and that makes the game think they are both baldi and student

Issues with 3 players or more (3 players are when double trouble game-mode is voteable)

Problems with the double trouble gamemode

  • 2 players are selected to be Baldi as intended however the student player is not given the student tag and is not teleported into map

  • Sometimes all players are baldi with no students

  • Sometimes there is no baldi player at all

  • Sometimes the game thinks that the second baldi player is also a student at the same time

I have listed the problems here is the script

Script (Only showing parts that handle voting and selecting baldi and teleporting players and starting the round module)


		for i, v in pairs(game.Players:GetPlayers()) do
			if v.PlayerGui:FindFirstChild("VotingGUI") then
			v.PlayerGui.VotingGUI.Votingframegametype["Survival buttion"].Votes.Text = "0"
			v.PlayerGui.VotingGUI.Votingframegametype["NoteBook gathering buttion"].Votes.Text = "0"
			v.PlayerGui.VotingGUI.Votingframegametype.Visible = true
				if v:FindFirstChild("Votedforamode").Value == true then
					v:FindFirstChild("Votedforamode").Value = false
				end
			end	
		end
		
		SurvivalVotes.Value = 0
		NoteBookgatheringVotes.Value = 0
		
		local VotedConnection1
		
		for i = 6,0,-1 do
			VotedConnection1 = GameTypeVoteEvent.OnServerEvent:Connect(function(player,Value)
				if Value == "Survival" then
					if player:FindFirstChild("Votedforamode").Value == false then
						player:FindFirstChild("Votedforamode").Value = true
						SurvivalVotes.Value = SurvivalVotes.Value + 1
						for i, v in pairs(game.Players:GetPlayers()) do
							v.PlayerGui.VotingGUI.Votingframegametype["Survival buttion"].Votes.Text = tostring(SurvivalVotes.Value)
						end	
					end	
				elseif Value == "NoteBook gathering" then
					if player:FindFirstChild("Votedforamode").Value == false then
						player:FindFirstChild("Votedforamode").Value = true
						NoteBookgatheringVotes.Value = NoteBookgatheringVotes.Value + 1
						for i, v in pairs(game.Players:GetPlayers()) do
							v.PlayerGui.VotingGUI.Votingframegametype["NoteBook gathering buttion"].Votes.Text = tostring(NoteBookgatheringVotes.Value)
						end
					end						
				end
			end)
			task.wait(1)
			Status.Value = "You have "..i.." seconds to vote for a gametype!"
		end
		VotedConnection1:Disconnect()
		
		if NoteBookgatheringVotes.Value > SurvivalVotes.Value then
			GameType.Value = "NoteBook gathering"
		elseif SurvivalVotes.Value > NoteBookgatheringVotes.Value then
			GameType.Value = "Survival"
		elseif SurvivalVotes.Value == NoteBookgatheringVotes.Value or SurvivalVotes.Value == 0 and NoteBookgatheringVotes.Value == 0 then
			local RandomGametype = Random.new()
			local Choose = RandomGametype:NextInteger(1,2)
			if Choose == 1 then
				GameType.Value = "Survival"
			elseif Choose == 2 then
				GameType.Value = "NoteBook gathering"
			end
		end
		
		
		for i, v in pairs(game.Players:GetPlayers()) do
			if v.PlayerGui:FindFirstChild("VotingGUI") then
				v.PlayerGui.VotingGUI.Votingframegametype.Visible = false
				v.PlayerGui.VotingGUI.VotingframegameMode["Double Trouble"].Votes.Text = "0"
				v.PlayerGui.VotingGUI.VotingframegameMode["Normal"].Votes.Text = "0"
				if game.Players.NumPlayers > 2 then
					v.PlayerGui.VotingGUI.VotingframegameMode.Visible = true
				end	
				if v:FindFirstChild("Votedforagamemode").Value == true then
					v:FindFirstChild("Votedforagamemode").Value = false
				end
			end	
		end
		
		NormalVotes.Value = 0
		DoubleTroubleVotes.Value = 0
		
		if game.Players.NumPlayers > 2 then
			Wasagamemodevote = true
			local VotedConnection
			for i = 6,0,-1 do
				VotedConnection = GameModeVoteEvent.OnServerEvent:Connect(function(player,Value)
					if Value == "Normal" then
						if player:FindFirstChild("Votedforagamemode").Value == false then
							player:FindFirstChild("Votedforagamemode").Value = true
							NormalVotes.Value = NormalVotes.Value + 1
							for i, v in pairs(game.Players:GetPlayers()) do
								v.PlayerGui.VotingGUI.VotingframegameMode.Normal.Votes.Text = tostring(NormalVotes.Value)
							end	
						end	
					elseif Value == "Double Trouble" then
						if player:FindFirstChild("Votedforagamemode").Value == false then
							player:FindFirstChild("Votedforagamemode").Value = true
							DoubleTroubleVotes.Value = DoubleTroubleVotes.Value + 1
							for i, v in pairs(game.Players:GetPlayers()) do
								v.PlayerGui.VotingGUI.VotingframegameMode["Double Trouble"].Votes.Text = tostring(DoubleTroubleVotes.Value)
							end
						end						
					end
				end)
				task.wait(1)
				Status.Value = "You have "..i.." seconds to vote for a gamemode!"
			end
			VotedConnection:Disconnect()
		else
			Wasagamemodevote = false
			GameMode.Value = "Normal"
		end
		
		if Wasagamemodevote == true then
			if DoubleTroubleVotes.Value > NormalVotes.Value then
				GameMode.Value = "Double Trouble"
			elseif NormalVotes.Value > DoubleTroubleVotes.Value then
				GameMode.Value = "Normal"
			elseif NormalVotes.Value == 0 and DoubleTroubleVotes.Value == 0 then
				GameMode.Value = "Normal"
			end
		end	
		
		for i, v in pairs(game.Players:GetPlayers()) do
			v.PlayerGui.VotingGUI.VotingframegameMode.Visible = false
			if v:FindFirstChild("Struggling") then
				v.Struggling.Value = false
			end
			if v:FindFirstChild("Hiding") then
				v.Hiding.Value = false
			end
			if v:FindFirstChild("isdoingmath") then
				v.isdoingmath.Value = false
			end
		end
		
		local AvailableToChooseforBaldi = {}
		
		for i, v in pairs(students) do
			if GameMode.Value == "Normal" then
				if v:FindFirstChild("WasBaldiLastRound").Value == false and v:FindFirstChild("AFK").Value == false then
					table.insert(AvailableToChooseforBaldi,v)
				end
			elseif GameMode.Value == "Double Trouble" and v:FindFirstChild("AFK").Value == false then
				table.insert(AvailableToChooseforBaldi,v)
			end	
		end
		
		local choosenBaldi = {}
		local RandomObj = Random.new()
		
		if GameMode.Value == "Normal" then
			for i, v in pairs(AvailableToChooseforBaldi) do
				local choosenv1 = AvailableToChooseforBaldi[RandomObj:NextInteger(1,#AvailableToChooseforBaldi)]
				if v == choosenv1 then
					table.remove(AvailableToChooseforBaldi,tonumber(v))
				end
				table.insert(choosenBaldi,v)
			end
		elseif GameMode.Value == "Double Trouble" then
			for i, v in pairs(AvailableToChooseforBaldi) do
				local choosenv1 = AvailableToChooseforBaldi[RandomObj:NextInteger(1,#AvailableToChooseforBaldi)]
				if v == choosenv1 then
					table.remove(AvailableToChooseforBaldi,tonumber(v))
					table.insert(choosenBaldi,v)
				end
				local choosenv2 = AvailableToChooseforBaldi[RandomObj:NextInteger(1,#AvailableToChooseforBaldi)]
				if v == choosenv2 then
					table.remove(AvailableToChooseforBaldi,tonumber(v))
					table.insert(choosenBaldi,v)
				end
			end
		end	

		for i, v in pairs(students) do
			if table.find(choosenBaldi,v) then
				table.remove(students,tonumber(v))
			end
		end
		
		task.wait(1)
		
		for i, v in pairs(students) do
			if v:FindFirstChild("WasBaldiLastRound").Value == true then
				v:FindFirstChild("WasBaldiLastRound").Value = false
			end
		end
		
		for i, v in pairs(students) do
			ShopAppearEvent:FireClient(v)
		end

		for i = 9,0,-1 do
			Status.Value = "Johnnys shop will disappear in "..i.." seconds! make sure to decide the item you will buy!"
			task.wait(1)
		end
		
		for i, v in pairs(students) do
			ShopDisappearEvent:FireClient(v)
		end
		
			for i, v in pairs(choosenBaldi) do
			modulescript.DressBaldi(v)
			end
		
			task.wait(0.5)
			modulescript.TeleportBaldi(choosenBaldi)
	
		if clonedschool:FindFirstChild("Spawnpoints") then
			modulescript.TeleportPlayers(students, clonedschool.Spawnpoints:GetChildren())
			for i, v in pairs(students) do
				if v:FindFirstChild("PurchasedItem").Value == true then
					local NewClonedPurchasedItem = ItemsFolder:FindFirstChild(v:FindFirstChild("ItemThatWasPurchased").Value):Clone()
					NewClonedPurchasedItem.Parent = v.Backpack
					v:FindFirstChild("PurchasedItem").Value = false
					v:FindFirstChild("ItemThatWasPurchased").Value = ""	
				end
			end	
		else
			warn("You didn't put spawns in map!")
		end	
		
		
		modulescript.InsertTag(students,"Student")
		modulescript.InsertBoolvalueTag(students,"isplaying")
		modulescript.InsertBoolvalueTag(students,"InDetention")
	
		modulescript.InsertTag(choosenBaldi,"Baldi")
		modulescript.InsertBoolvalueTag(choosenBaldi,"IsStunned")
		
		
		if GameType.Value == "Survival" then
			for i, v in pairs(clonedschool.NoteBooks:GetChildren()) do
				v:Destroy()
			end
			modulescript.StartRoundSurvival(320,choosenBaldi,clonedschool)
		elseif GameType.Value == "NoteBook gathering" then
			modulescript.StartRoundNotebookgather(380,choosenBaldi,clonedschool)
		end	

I have been trying to fix the issues all day but to no avail and due to how severe these bugs are my game is now private because if them so that’s why I’m making this devforum post any help is appreciated!

2 Likes

I didn’t read everything, but this jumped out as me as problematic. You’re connecting this event again every second… And probably never disconnecting it. The result of this is that if someone fires the event, it runs the response code multiple times, which throws off the vote count.

You should make sure the :Connect line runs only once, and that it checks a condition instead like if not isPickingRound then return end, or alternatively save the connection like local votedConnection = gameModeVoteEvent.OnServerEvent:Connect(...) and later call votedConnection:Disconnect() when you’re done listening.

1 Like

I implemented this but it didn’t really fixed any of the problems I listed

1 Like

Please post your latest code so folks can help track down the issue

Posted the updated version of the code

1 Like

I still see a couple :Connect() calls happening inside a for loop like I mentioned before, not sure if I’m still seeing outdated code or if you haven’t fixed it everywhere yet