Repetitive Voting Choice

Can someone fixed my voting code (server)

The problem is some time choice is repetitive

Here my code :

local VotingSystem = require(script.Parent.VotingSystem)

local gamemode = {"Low Gravity", "Normal", "Sword Fight", "Underwater", "Taco Rain", "Night"}

local Dragable = game.ServerStorage.Dragable:Clone()

Dragable.Parent = game.Workspace.CrossRoad.Object

local voting = coroutine.wrap(function()
	while true do
		local Message = game.ReplicatedStorage.MessageEvent
		task.wait(180)
		Message:FireAllClients("Changing Gamemode in 2 minute")
		task.wait(120)
		Message:FireAllClients("Changing Gamemode in 1 minute")
		task.wait(60)
		Message:FireAllClients("Changing Gamemode in 30 second")
		task.wait(30)
		Message:FireAllClients("Changing Gamemode in 10 second")
		task.wait(10)
		local Choices = {gamemode[math.random(#gamemode)],gamemode[math.random(#gamemode)],gamemode[math.random(#gamemode)]}
		local ChooseChoice = coroutine.wrap(function()
			while not Choices[1] == not Choices[2] and not Choices[2] == not Choices[1] and not Choices[3] == not Choices[1] and not Choices[2] == not Choices[3] and not Choices[3] == not Choices[2] do
				if Choices[2] == Choices[1] or Choices[1] == Choices[3] then
					Choices[2] = gamemode[math.random(#gamemode)]
					task.wait()
				elseif Choices[3] == Choices[1] or Choices[1] == Choices[3] then
					Choices[3] = gamemode[math.random(#gamemode)]
					task.wait()
				elseif Choices[3] == Choices[2] or Choices[2] == Choices[3] then
					Choices[3] = gamemode[math.random(#gamemode)]
					task.wait()
				elseif not Choices[1] == not Choices[2] and not Choices[2] == not Choices[1] and not Choices[3] == not Choices[1] and not Choices[2] == not Choices[3] and not Choices[3] == not Choices[2] then
					print("Perfect")
					task.wait()
					return
				end
			end
		end)

		ChooseChoice()

		local Win = VotingSystem:SendVote(Choices)
		print(Win, "won the vote!!!!!!")

		if Win == "Low Gravity" then
			game.Workspace.Gravity = 50
		else 
			game.Workspace.Gravity = 196.2
		end

		if Win == "Night" then
			local Lighting = game:GetService("Lighting")
			Lighting.ClockTime = 0
		else
			local Lighting = game:GetService("Lighting")
			Lighting.ClockTime = 7
		end

		if Win == "Sword Fight" then
			if game.StarterPack:FindFirstChild("ClassicSword") then
				game.StarterPack.ClassicSword.Parent = game.ServerStorage
			end
			game.ServerStorage.ClassicSword.Parent = game.StarterPack
			game.StarterPlayer.StarterCharacterScripts["Ragdoll Damage"].Value = true
		else
			if not game.ServerStorage:FindFirstChild("ClassicSword") then
				game.StarterPack.ClassicSword.Parent = game.ServerStorage
			end
			game.StarterPlayer.StarterCharacterScripts["Ragdoll Damage"].Value = false
		end

		if Win == "Underwater" then
			if game.Workspace:FindFirstChild("WaterPart") then
				game.Workspace.WaterPart.Parent = game.ServerStorage
			end
			game.ServerStorage.WaterPart.Parent = game.Workspace
			game.Workspace.Gravity = 60
		else
			if not game.ServerStorage:FindFirstChild("WaterPart") then
				game.Workspace.WaterPart.Parent = game.ServerStorage
			end
		end

		if Win == "Taco Rain" then
			if game.Workspace:FindFirstChild("Taco Spawner") then
				game.Workspace["Taco Spawner"].Parent = game.ServerStorage
			end
			game.ServerStorage["Taco Spawner"].Parent = game.Workspace
		else
			if not game.ServerStorage:FindFirstChild("Taco Spawner") then
				game.Workspace["Taco Spawner"].Parent = game.ServerStorage
			end
		end

		for index,player in pairs(game:GetService("Players"):GetPlayers()) do
			player.Character.Ragdoll.Value = false
			player:LoadCharacter()
		end
		game.Workspace.CrossRoad.Object.Dragable:Destroy()
		for i, v in pairs(game.Workspace.CrossRoad.Object.Taco:GetChildren()) do
			if v:IsA("BasePart") then
				v:Destroy()
			end

		end
		local NewDragable = game.ServerStorage.Dragable:Clone()
		NewDragable.Parent = game.Workspace.CrossRoad.Object
		Message:FireAllClients("Changed Gamemode to "..Win)
	end

end)

voting()
2 Likes

I think what you want is to make the voting system gives out 3 different choices from the list.

local gamemode = {"Low Gravity", "Normal", "Sword Fight", "Underwater", "Taco Rain", "Night"}
local gamemodesToChoose = {}
local Choices = {}
function pickGamemodesToVote()
	--//Reset the pick table
	gamemodesToChoose = {}
	for _,v in pairs(gamemode) do
		table.insert(gamemodesToChoose,v)
	end
	
	--//Picking from that table and removing what have been picked
	for i=1, 3 do
		local randomNum = math.random(#gamemodesToChoose)
		Choices[i] = gamemodesToChoose[randomNum]
		table.remove(gamemodesToChoose,randomNum)
	end
end

pickGamemodesToVote()
for _,v in pairs(Choices) do
	print(v)
end

This script use another table with the same values as the gamemode table you gave but after picking a map, it removes it so that the same map can’t be chosen again.

2 Likes

Oh, Thank you so much
i can fix it now.

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