I’m trying to make voting pads, where a vote is counted as long as the player stands on the pad. The script doesn’t work though, so I’m probably doing something wrong. Would be great if I could get some tips on how to fix it Thanks in advance.
CurrentStatus = ‘Voting’
local Map1Votes = {}
local Map2Votes = {}
local Map3Votes = {}
Vote1.VotePad.Touched:connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not Player or not CurrentStatus == 'Voting' then return end
for index, touch in pairs(Map1Votes) do
if Player ~= touch then
table.insert(Map1Votes, Player)
Vote1.VotePad.GUI.Frame.Amount.Text = #Map1Votes
print(unpack(Map1Votes))
end
end
end)
Vote1.VotePad.TouchEnded:connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not Player or not CurrentStatus == 'Voting' then return end
for index, touch in pairs(Map1Votes) do
if Player == touch then
table.remove(Map1Votes, index)
Vote1.VotePad.GUI.Frame.Amount.Text = #Map1Votes
print(unpack(Map1Votes))
end
end
end)
local point1 = pad1.Position + Vector3.new(pad1.Size.X/2, 0, pad1.Size.Z/2)
local point2 = pad1.Position + Vector3.new(-(pad1.Size.X/2), 15, -(pad1.Size.Z/2))
local region = Region3.new(point1, point2)
while wait() do
for x, player in pairs(game.Players:GetPlayers()) do
-- check players are in the region --
-- continue logic etc. --
end
end
2 parts of the character begin touching the votespace. Character is added to the vote list.
1 part of the character stops touching the votespace. Character is removed from the vote list.
Even though the character is still in the votespace, when any part of them leaves it, they are counted as totally leaving it. With r15, lots of parts could be entering and leaving he votespace as the character walks onto/into it. And also parts could be leaving it frequently too. All the code does is keep track if the last event was a part entering or leaving.
I guess if you wanted to be overly efficient, you could keep a table of all the players in the server’s HumanoidRootParts, and pass that as a whitelist to the region3 function.
You might want to do if not Player or not (CurrentStatus == 'Voting') then return end
instead of if not Player or not CurrentStatus == 'Voting' then return end
I’ve had problems arise from small things like that.
If this doesn’t fix it, could you explain your error or problem a little bit more?
That doesn’t work either. I’ve found out what’s not working tho. It’s the lines highlighted in gray.
Vote1.VotePad.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not Player or not (CurrentStatus == 'Voting') then return end
--[[for index, touch in pairs(Map1Votes) do
if Player ~= touch then]]
table.insert(Map1Votes, Player)
Vote1.VotePad.GUI.Frame.Amount.Text = #Map1Votes
print(unpack(Map1Votes))
--end
--end
end)