[NOT SOLVED] For i, loops acting weird

@Y_VRN @msix29 think I found the problem But I don’t know how to fix it.
If I join the queue to fast it breaks, the countdown counts down (like the other time when I joined the qeueu)

if I wait a bit and join it resets the timer, I think it’s because from the wait.

Could it be this block of code?

for i=1, 10 do -- < More specifically this.
	Signals.Status.Value = "Looking for Players  (" .. #InQueue .. ")"
	if #InQueue == MaxPlayers then  break else RemoteEvents.VotingStopped:FireAllClients() end
	task.wait(1)
end

You might not need the for loop, or most of the block even. Try this:


while Timer > 0 do
	local IsFull = (#InQueue == MaxPlayers)

	if IsFull then
		Signals.Status.Value = "Voting Has Began (" .. Timer .. ")"
		if not VotingStarted then -- Fire all clients once to save bandwidth
			RemoteEvents.VotingBegan:FireAllClients()
			VotingStated = true
		end
		Timer -= 1
	else
		Signals.Status.Value = "Looking for Players  (" .. #InQueue .. ")"
		if VotingStarted then -- Fire all clients once to save bandwidth
			RemoteEvents.VotingStopped:FireAllClients()
			VotingStated = false
		end
		Timer = IntermissionTimer
	end
	task.wait(1)
end

bruh i am getting really bad at editing

it doesn’t work here is the code incase i did something wrong

function Voting()

	if (#InQueue == MaxPlayers and Signals.MatchStarted.Value == false) and VotingStarted == false then 
		VotingStarted = true


		repeat
			task.wait(.1)
			local RandomMap1 = ReplicatedStorage.Maps:GetChildren()[math.random(1, #ReplicatedStorage.Maps:GetChildren())]
			local RandomMap2 =  ReplicatedStorage.Maps:GetChildren()[math.random(1, #ReplicatedStorage.Maps:GetChildren())]
			local RandomMap3 =  ReplicatedStorage.Maps:GetChildren()[math.random(1, #ReplicatedStorage.Maps:GetChildren())]
			RandomMap1Var = RandomMap1
			RandomMap2Var = RandomMap2
			RandomMap3Var = RandomMap3

		until (RandomMap1 ~= RandomMap2) and (RandomMap3 ~= RandomMap2) and (RandomMap1 ~= RandomMap3)
		if (RandomMap1Var ~= nil and RandomMap2Var ~= nil) and RandomMap3Var ~= nil then
			RemoteEvents.VoteChoices:FireAllClients(RandomMap1Var, RandomMap2Var, RandomMap3Var)
		end

		local Timer = IntermissionTime

		while Timer > 0 do
			local IsFull = (#InQueue == MaxPlayers)

			if IsFull then
				Signals.Status.Value = "Voting Has Began (" .. Timer .. ")"
				if not VotingStarted then -- Fire all clients once to save bandwidth
					RemoteEvents.VotingBegan:FireAllClients()
					VotingStarted = true
				end
				Timer -= 1
			else
				Signals.Status.Value = "Looking for Players  (" .. #InQueue .. ")"
				if VotingStarted then -- Fire all clients once to save bandwidth
					RemoteEvents.VotingStopped:FireAllClients()
					VotingStarted = false
				end
				Timer = IntermissionTime
			end
			task.wait(1)
		end
		
		VotingStarted = true
		Signals.MatchStarted.Value = true
		Signals.Status.Value = "A Match is Already in The Proccess Please Wait.."
		RemoteEvents.VotingStopped:FireAllClients()
	end
end

Have you checked for output errors? Can you send what the output has said, if any?

There are no errors, Plus the intermission plays 2 times at the same time so your code doesn’t work.

Hi everyone, I fixed it by adding a debounce on the Client when the Player joins the queue (Cooldown) This fixed the loop (for some reason I have no idea why to be honest), Thanks @msix29 for the help!

2 Likes

Debounces are your friend - nice job.

1 Like

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