You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
get rid of this error -
What is the issue? Include screenshots / videos if possible!
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
local API = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RemoteHandler = require(script.Parent.Parent.RemoteHandler)
local Verificator = require(script.Parent.Parent.Verificator)
local Components = require(script.Parent.Parent.Components)
local ClientFunctions = require(script.Parent.Parent.ClientFunctions)
local NotificationHandler = require(script.Parent.Parent.NotificationHandler)
local Elections = require(ReplicatedStorage.Databases.Elections)
local player = Players.LocalPlayer
local canVote = RemoteHandler.Func.new("CanVote")
local submitVote = RemoteHandler.Event.new("SubmitVote")
local ShuffleTable = function(t)
local random = Random.new(tick() * 1000)
random:NextNumber()
random:NextNumber()
random:NextNumber()
local n = #t
while n > 2 do
local k = random:NextInteger(1, n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
return t
end
function API.Verify(inter)
return {
[Enum.KeyCode.F] = "Use Voting Booth"
}
end
local debounce = false
function API.Press(inputObject, interact, context)
if not debounce and inputObject.UserInputState == Enum.UserInputState.End then
debounce = true
context:Remove()
if not next(Elections) then
NotificationHandler.NewNotification("There are no elections currently available.", "No Elections!", "Red")
debounce = false
return
end
do
local actionDebounce = false
local submitDebounce = false
ClientFunctions.MovementEnable(false)
local hashedRes = {}
local res = canVote:Invoke(interact.Id)
for i = 1, #res do
local v = res[i]
hashedRes[v] = true
end
local window = Components.Window.new("Voting System")
window:AddComponent(Components.TextLabel.new("Choose the election you would like to vote in:"))
for i, v in pairs(Elections) do
do
local thisButton = Components.Button.new(v.Name, not hashedRes[i], true)
thisButton.MouseClick:Connect(function()
if thisButton.Enabled and not actionDebounce then
actionDebounce = true
if hashedRes[i] then
window:NewPage(2)
if v.Question then
window:AddComponent(Components.TextLabel.new(v.Question), 2)
else
window:AddComponent(Components.TextLabel.new((v.Type == "STV" or v.Type == "AV") and "Rank the candidates in order of preference, 1 (most preferred) to a maximum of " .. #v.Options .. " (least preferred):" or "Select 1 candidate from the list:"), 2)
end
do
local ballotPane = Components.BallotPane.new(v.Type == "STV" or v.Type == "AV")
local submit = Components.Button.new("SUBMIT")
local listTable = {}
for k, cand in pairs(v.Options) do
table.insert(listTable, {
k,
cand[1],
cand[2]
})
end
ShuffleTable(listTable)
ballotPane:SetItemList(listTable)
local function VerifyInput()
if v.Type == "STV" or v.Type == "AV" then
local inputs = {}
local gotSomething = false
local returnTable = {}
for _, box in pairs(ballotPane.Boxes) do
local boxText = box.Text
local boxNumber = tonumber(boxText)
if boxNumber and v.Options[boxNumber] then
if inputs[boxNumber] then
return
end
inputs[boxNumber] = true
returnTable[boxNumber] = tonumber(box.Parent.Name)
gotSomething = true
elseif boxText ~= "" then
return
end
end
local lastGood = true
for i = 1, #v.Options do
if inputs[i] then
if not lastGood then
return
end
lastGood = true
else
lastGood = false
end
end
if gotSomething then
return returnTable
end
else
return ballotPane.Selected
end
end
submit.MouseClick:Connect(function()
if not submitDebounce then
submitDebounce = true
local inputResult = VerifyInput()
if inputResult then
submitVote:Fire(interact.Id, i, inputResult)
else
NotificationHandler.NewNotification("Invalid input.", "Voting Error!", "Red")
end
window:Close()
end
end)
window:AddComponent(ballotPane, 2)
window:AddComponent(submit, 2)
window:SwitchPage(2)
end
else
window:Close()
end
end
end)
window:AddComponent(thisButton)
end
end
window.OnHide:Connect(function()
ClientFunctions.MovementEnable(true)
wait(0.5)
debounce = false
end)
window:Show()
end
end
end
return API
Line 47:
for i = 1, #res do
