Hello. Attempting to script a clean debris queue pad, I don’t know how to script the voting part.
local pad = script.Parent
local text = pad.VoteGui.TextLabel
local voted = pad.Voted
local ready = pad.Ready
pad.Touched:Connect(function()
if ready == true then
ready = false
for _, stations in pairs(game.Workspace:GetDescendants()) do
if stations:IsA("Model") and stations.Name == "Station" then
for _, vehicles in pairs(stations:GetChildren()) do
if vehicles:IsA("Model") then
vehicles:Destroy()
end
end
end
end
for i = 60, 0, -1 do
text.Text = "On Cooldown (" .. i ..")"
print("Ready to vote")
ready.Value = true
wait(1)
end
text.Text = "Clean Debris (0/0)"
end
end)
I don’t know how your system is really set up so I can’t actually code it, but assuming you can access the voting GUI and use .MouseButton1Click from the server, you can count votes through using that and reset the votes each round. The voting can be enabled or disabled with ready.Value.
In that case, you can determine how many players are in the area using whatever function it’s called. Probably in workspace. I’d reference the object browser if I were you.
I believe it is GetPartBoundsInBox if I remember correctly. You can additionally make the floor a unique material and check the Humanoid.FloorMaterial property.
To implement voting, you can use RemoteEvents to communicate between the client and server scripts. Keep track of the number of players who have voted and trigger the cleanup process once a certain threshold is reached.
local playercount = #game.Players:GetPlayers()
local count = 0
pad.Touched:Connect(function()
count += 1
if count == playercount * 0.7 then
-- action
end
end)
.Touched is not accurate in that regard because characters have multiple parts. You can detect if the name is the humanoid root part, and make a hitbox for it. You’d need to undo the vote when the player leaves using .TouchEnded.
pad.Touched:Connect(function(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
count += 1
if count == playercount * 0.7 then
-- action
end
end
end)
local pad = script.Parent
local text = pad.VoteGui.TextLabel
local voted = pad.Voted
local ready = pad.Ready
local playercount = #game.Players:GetPlayers()
wait(.1)
voted.Value = 0
voted:GetPropertyChangedSignal("Value"):Connect(function()
text.Text = "Clean Debris (" .. voted.Value .. "/" .. playercount .. ")"
end)
pad.Touched:Connect(function(hit)
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
voted.Value = voted.Value + 1
print("Player has voted")
if voted == playercount * 0.7 then
voted.Value = 0
for _, vehicles in pairs(game.Workspace:GetDescendants()) do
if vehicles:IsA("Model") and vehicles.Parent.Name == "Station" then
vehicles:Destroy()
end
end
print("Sucessfully cleaned up")
end
end
end)
My mistake. Your touch pad is a pad and not a hitbox. Assuming you don’t want the player to be able to vote again, this should also work.
With that being said, your current code will cause multiple votes allowed by the same person because you’re not checking if they’ve already voted. This can be fixed with a table.
--put in the top of the script
local voters = {}
--after if (human ~= nil) then, put
if not table.find(voters, human) then
table.insert(voters, human)
else
return
end
--When the round ends, or if votes are completed, put
table.clear(voters)
Unless I’m not understanding how your game design works, this should work just fine. One thing to note though is that if the player resets their character, they will be able to vote again.