I want to make a voting pad where voters can cast a vote to kick the leader. I am making an array and inserting the player's name into the array however the issue I come across are two things
- Knowing the difference between an empty entry and an entry that already has another player's name in it.
- Making sure the current player's name is not in any index in the array.
Here is my code so far
local voterArray = {""}
local debounce = script.Parent.debounce
function onTouched(hit)
if debounce.Value == true then
debounce.Value = false
for index, value in ipairs(voterArray) do
print(index, '=', value)
if value == "" then --Make sure value in each index is empty, if its not empty its somebody else's player name already in there
if value ~= hit.Parent then --if a value in an index does not contain the touched player's name then
addPlayer(hit.Parent)
else
game.Workspace['Vote to kick Leaderr'].Name = "You already voted"
self.BrickColor = BrickColor.new("Bright blue")
wait(2)
game.Workspace['You already voted'].Name = "Vote to kick Leader"
self.BrickColor = BrickColor.new("Bright red")
wait(3)
end
end
end
debounce.Value = true
end
end
function addPlayer(player)
local playerName = player
table.insert(voterArray, playerName)
print("added player to array")
end

3 comments
What do you mean by "check if a player is in an array?" Are you trying to check if it's an actual player? If you're using the PlayerAdded function or GetPlayers function, it'll always return an actual player.
No I am checking if a player's name is already inside the array to prevent the same player from voting twice.
Then you would compare the player's name to a value in the table, via iterating over the table, or using the brackets thing (forgot name ;-;). ([player.Name] = Value)