So I was making a voting system But I’ve ran into a Problem I’ve made a countdown But a problem appeared basically when the player joins a queue and leaves it at 5 seconds (any number, it’s just an example) and then joins sometimes the loop will count from 5 to 0 instead of 10 to 0
Here is my Code
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
for i = 10, 0, -1 do
if #InQueue == MaxPlayers then
Signals.Status.Value = "Voting Has Began (" .. i .. ")"
RemoteEvents.VotingBegan:FireAllClients()
task.wait(1)
else
for i=1, 10 do
Signals.Status.Value = "Looking for Players (" .. #InQueue .. ")"
if #InQueue == MaxPlayers then break else RemoteEvents.VotingStopped:FireAllClients() end
task.wait(1)
end
if #InQueue == MaxPlayers then
VotingStarted = false
return Voting()
end
end
end
VotingStarted = true
Signals.MatchStarted.Value = true
Signals.Status.Value = "A Match is Already in The Proccess Please Wait.."
RemoteEvents.VotingStopped:FireAllClients()
end
end
I’m not a very good scripter, so I’m not sure if I can manage to solve this problem, but what is Signals.MatchStarted? It could be a small mistake related to it.
Told you, I’m not a good scripter, but I was just asking because local scripts can’t access ServerStorage and ServerScriptService, so if your checking the value in one of those, it wont work. Sorry, but I probably can’t solve this problem.
I didn’t give any code, I was just quoting the part that might be the problem. Anyways, if this won’t work, sorry but I can’t help. Hopefully someone better at scripting will help you.
You’re right. If the top loop were to run 10 times and it goes by the “else” 10 times then the next for loop will be run 10 times too and the code inside that second for loop 100 times. I don’t think that’s supposed to happen.
Could you go through and explain what each part of your code does? Why are you checking if the total InQueue equals MaxPlayers 10 times? Is this some sort of countdown? And why run another for loop inside 10 times?
it’s a bit hard to explain but I’ll explain Basically the player queues up it will add them to the table called “InQueues” when each player queues up we connect to the voting function in the voting function we check if the players in the queue table is equal to the Max players and the game hasn’t started a match, etc
The problem is the player can exit the queue while in the voting session that’s why I’m doing that.