Issues with debris cleaning queue pad

Hello. I have a queue pad which cleans the debris in the server once enough players steps on it.
But, I have a few issues:

  • The queue pad doesn’t display the players required to vote to perform the action.
  • Players cannot submit votes after the cooldown is over.
  • It refuses to clean some models sharing the same parent name as others, saying its indexing with nil:

Script:

local pad = script.Parent
local text = pad.VoteGui.TextLabel
local voted = pad.Voted
local ready = pad.Ready
local playercount = #game.Players:GetPlayers()

local voters = {}

wait(.1)
voted.Value = 0

voted:GetPropertyChangedSignal("Value"):Connect(function()
	text.Text = "Clean Debris (" .. voted.Value .. "/" .. math.ceil(playercount * .7) .. ")"
end)

pad.Touched:Connect(function(hit)
	if ready.Value == true then
		local human = hit.Parent:findFirstChild("Humanoid") 
		if (human ~= nil ) then 
			if not table.find(voters, human) then
				table.insert(voters, human)
				voted.Value = voted.Value + 1
				print("Player has voted")
			else
				return
			end
			if voted.Value / playercount >= .7 then
				voted.Value = 0
				ready.Value = false
				for _, vehicles in pairs(game.Workspace:GetDescendants()) do
					if vehicles:IsA("Model") and vehicles.Parent.Name == "Station" and vehicles.Parent:IsA("Model") then
						vehicles:Destroy()
					end
				end
				table.clear(voters)
				pad.Color = Color3.new(0.00784314, 0.329412, 0.435294)
				print("Sucessfully cleaned up")
				for i = 60, 0, -1 do
					text.Text = "On Cooldown (" .. i .. ")"
					wait(1)
				end
				ready.Value = true
				pad.Color = Color3.new(0.0156863, 0.686275, 0.92549)
				text.Text = "Clean Debris (" .. voted.Value .. "/" .. playercount * .7 .. ")"
			end
		end
	end
end)
1 Like
local pad = script.Parent
local text = pad.VoteGui.TextLabel
local voted = pad.Voted
local ready = pad.Ready
local playercount = #game.Players:GetPlayers()

local voters = {}

wait(0.1)
voted.Value = 0

voted:GetPropertyChangedSignal("Value"):Connect(function()
    text.Text = "Clean Debris (" .. voted.Value .. "/" .. math.ceil(playercount * 0.7) .. ")"
end)

pad.Touched:Connect(function(hit)
    if ready.Value == true then
        local human = hit.Parent:FindFirstChild("Humanoid") 
        if human then 
            if not table.find(voters, human) then
                table.insert(voters, human)
                voted.Value = voted.Value + 1
                print("Player has voted")
            else
                return
            end
            if voted.Value / playercount >= 0.7 then
                voted.Value = 0
                ready.Value = false
                
                for _, vehicles in pairs(game.Workspace:GetDescendants()) do
                    if vehicles:IsA("Model") and vehicles.Parent and vehicles.Parent:IsA("Model") and vehicles.Parent.Name == "Station" then
                        vehicles:Destroy()
                    end
                end
                
                table.clear(voters)
                pad.Color = Color3.new(0.00784314, 0.329412, 0.435294)
                print("Successfully cleaned up")
                
                for i = 60, 0, -1 do
                    text.Text = "On Cooldown (" .. i .. ")"
                    wait(1)
                end
                
                ready.Value = true
                pad.Color = Color3.new(0.0156863, 0.686275, 0.92549)
                text.Text = "Clean Debris (" .. voted.Value .. "/" .. playercount * 0.7 .. ")"
            end
        end
    end
end)
1 Like

The script fixed 2 problems, but it still doesn’t display the amount of players needed to vote:
image

1 Like