I am wanting a brick that counts how many players are standing on it, like in map voting. This is what I have. I have no idea why this doesn't work. When I stand on it, it prints 2 instead of 1. Anyone know the problem? Thank you.
--[[_G.idiots = 0
function Touched(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild("foreigner").TeamColor then
end
_G.idiots = _G.idiots + 1
print(_G.idiots)
end
end
script.Parent.Touched:Connect(Touched)]]--
local Player
local Part = workspace.pad.Part
local PlayersTouching = {} --Creating a table. You and I are currently touching the part.
game.Players.PlayerAdded:Connect(function(Plr)
Player = Plr
end)
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
table.insert(PlayersTouching, Hit.Parent.Name) --Putting the name of the player in the table
end
end)
Part.TouchEnded:Connect(function(Hit) --If they stop touching the part
if Hit.Parent:FindFirstChild("Humanoid") then
for i,v in pairs(PlayersTouching) do
if v == Player.Name then
PlayersTouching[i] = nil --Removing the player from the table
end
end
end
end)
while true do
print(#PlayersTouching)
wait(1)
end

4 comments
Wow, was that map a bad map? Was that how the variable name was created?
They are called idiots because the people using the pad always act like idiots
Use table.remove on line 34
Im going to stick with, PlayersTouching[i] = nil. Table.remove didn't work