#Script voting not working (shit code)

1 messages · Page 1 of 1 (latest)

desert rose
#

Help

#
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2

local StarterGUI = game:GetService("StarterGui")


local TableOfPart1 = {}
local TableOfPart2 = {}


local debounce = false


Part1.Touched:Connect(function(hit)
    if debounce == true then return end
    if debounce == false then
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)


        if player then
            local name = player.Name
            local Check = table.find(TableOfPart2, player.Name)
            local Check2 = table.find(TableOfPart1, player.Name)
            
            
            if Check or Check2 then
                print("Player has already voted")
            else
                
                print("Player has not voted already")
                table.insert(TableOfPart1, player.Name)
                debounce = false
                return TableOfPart1
                
            end

        end
    end
    
end)

Part2.Touched:Connect(function(hit)
    if debounce == true then return end
    if debounce == false then
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if player then
            local name = player.Name
            local Check = table.find(TableOfPart1, player.Name)
            local Check2 = table.find(TableOfPart2, player.Name)
            if Check or Check2 then 
                print("Player has already voted.")
            else
                print("Player has not already voted")
                table.insert(TableOfPart2, player.Name)
                debounce = false
                return TableOfPart2

            end
        end
    end

end)


for i = 20, 1, -1 do
    task.wait(1)
    print(i .. "seconds left.")
    print(TableOfPart1, TableOfPart2)
    
end

task.wait(1)

#

TableOfPart1 is used for a part named Part1 in workspace

#

TableOfPart2 is used for a part named Part2 in workspace

#

I'm making a voting system

#

So basically players vote and yeah after countdown ends it does anyhing

bright sonnet
#

does it set debounce back to false in all cases?

#

like if it touches another part instead of a player, does the debounce get reset?

#

what's happening there?

ocean cradle
desert rose
desert rose