I am trying to make a voting system where the players press a button and send over what they voted for, however whenever I try and pass on the value for what they voted for the server keeps on thinking the value is the player
Script inside of button
local function Vote ()
local player = game:GetService("Players").LocalPlayer
local optionPicked = 1
local function sendVote ()
game:GetService("ReplicatedStorage").RemoteEvents.Vote:FireServer(player, optionPicked)
end
game:GetService("ReplicatedStorage").RemoteEvents.Vote.OnClientEvent:Connect(sendVote)
end
script.Parent.MouseButton1Down:Connect(Vote)
Script inside of serverScriptService managing the game
local ThemeManager = require(game:GetService("ServerStorage").ThemeManager)
local votes = {}
wait(5)
game:GetService("ReplicatedStorage").RemoteEvents.Vote:FireAllClients()
local function voteCount (player, optionPicked)
table.insert(votes, optionPicked)
print(optionPicked)
--print option picked keeps on printing out a player name
end
game:GetService("ReplicatedStorage").RemoteEvents.Vote.OnServerEvent:Connect(voteCount)
wait(1)
ThemeManager.Votes()
Module script
function Theme.Votes (votes)
local option1Votes = 0
local option2Votes = 0
local option3Votes = 0
local result
for i,v in votes do
--an error keeps on happening here where it thinks the table votes is a nil value
if v == 1 then
--1 is option 1
option1Votes += 1
elseif v == 2 then
--2 is option 2
option2Votes += 1
elseif v == 3 then
--3 is option 3
option3Votes += 1
end
end
--RESULTS
if option1Votes > option2Votes and option3Votes then
--1 is option 1
result = 1
elseif option2Votes > option1Votes and option3Votes then
--2 is option 2
result = 2
elseif option3Votes > option2Votes and option1Votes then
--3 is option 3
result = 3
--TIES
elseif option1Votes == option2Votes then
local tie = math.random(1,2)
if tie == 1 then
result = 1
else
result = 2
end
elseif option1Votes == option3Votes then
local tie = math.random(1,2)
if tie == 1 then
result = 1
else
result = 3
end
elseif option2Votes == option3Votes then
local tie = math.random(1,2)
if tie == 1 then
result = 2
else
result = 3
end
end
return result
end
return Theme
Please help me the code has got 2 errors that I haven’t found in any other places.
Thanks in advance.