I have an MM2 inspired game in the works and I've been trying to get the vote system working. After a while I ended up making it work, or so I thought. For one person, the voting works fine. For 2 people, it changes vote whenever a player steps on another map button, as if they both share the same vote, sometimes flashing 2 for a split second when they stand on the same button. Could someone explain to me what I'm doing wrong?

local Button1 = script.Parent.Button1.StepOn
local Button2 = script.Parent.Button2.StepOn
local Button3 = script.Parent.Button3.StepOn
local Board1 = script.Parent.Parent.VoteBoards.VoteBoard1
local Board2 = script.Parent.Parent.VoteBoards.VoteBoard2
local Board3 = script.Parent.Parent.VoteBoards.VoteBoard3
local BoardMap1 = Board1.SurfaceGui.NameOfMap
local BoardImage1 = Board1.SurfaceGui.ImageLabel
local BoardVotes1 = Board1.SurfaceGui.VoteCounter
local BoardMap2 = Board2.SurfaceGui.NameOfMap
local BoardImage2 = Board2.SurfaceGui.ImageLabel
local BoardVotes2 = Board2.SurfaceGui.VoteCounter
local BoardMap3 = Board3.SurfaceGui.NameOfMap
local BoardImage3 = Board3.SurfaceGui.ImageLabel
local BoardVotes3 = Board3.SurfaceGui.VoteCounter

while Button1.BrickColor == BrickColor.new("Shamrock") do
	--the player arrays are for each button
	local players1 = {}
	local players2 = {}
	local players3 = {}
	function touch(hit,plrs,vote,button)
		if game.Players:GetPlayerFromCharacter(hit.Parent) then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local dupe = false
			for i,v in pairs(plrs) do
				if v == player then
					dupe = true
				end
			end
			if dupe == false then
				local change = {false}
				if plrs == players1 then
					for i,v in pairs(players2) do
						if v == player then
							change = {true,players2[i]}
						end
					end
					if change == false then
						for i,v in pairs(players3) do
							if v == player then
								change = {true,players3[i]}
							end
						end
					end
				end
				if plrs == players2 then
					for i,v in pairs(players1) do
						if v == player then
							change = {true,players1[i]}
						end
					end
					if change == false then
						for i,v in pairs(players3) do
							if v == player then
								change = {true,players3[i]}
							end
						end
					end
				end
				if plrs == players3 then
					for i,v in pairs(players1) do
						if v == player then
							change = {true,players1[i]}
						end
					end
					if change == false then
						for i,v in pairs(players2) do
							if v == player then
								change = {true,players2[i]}
							end
						end
					end
				end
				if change[1] == true then
					change[2] = nil
				end
				table.insert(plrs,player)
				BoardVotes1.Text = #players1
				BoardVotes2.Text = #players2
				BoardVotes3.Text = #players3
			end
		end
	end
	Button1.Touched:Connect(function(hit)
		touch(hit,players1,BoardVotes1,Button1)
	end)
	Button2.Touched:Connect(function(hit)
		touch(hit,players2,BoardVotes2,Button2)
	end)
	Button3.Touched:Connect(function(hit)
		touch(hit,players3,BoardVotes3,Button3)
	end)
	wait()
end

Thanks!

3 comments

0

additional information if needed: the script is serversided, and there was no error.

0

All of this just to vote?

0

3 physical buttons in one script so ig yeah