Im frustrated because I don't know why you cant say "if not TABLE[hit.Parent.Name] then"
I dont know how to say it.. its in a server script for all you people who ask
--||VotePad local Config = script.Parent.Parent.Config local VotesGUI = script.Parent.Parent.ConnectedBoard.VotesGui local VoteDisplay = VotesGUI.VoteDisplay local VoteImage = VotesGUI.Image local DeniedPlayers = {} local debounce = true script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if not DeniedPlayers[hit.Parent.Name] then -- why does this not work if not debounce then return end debounce = false Config.VotesAmount.Value = Config.VotesAmount.Value + 1 script.Parent.Color = Color3.fromRGB(0,255,0) table.insert(DeniedPlayers, hit.Parent.Name) print(DeniedPlayers) wait(1) debounce = true end end end)
You cannot do that with numeric indices. However, you can do that with string indices. A simple example:
local array = {} array["hello"] = true print(not array["hello"])
Side note for future reference:
local array = {} array["hello"] = true -- is the same in Lua as array.hello = true
Putting this all together, we can create a debounce with player names as the indices. I hope this helps. Have a great day scripting!
Edit with example:
local players = game:GetService("Players") -- the recommended way to get any service, including players script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = players:GetPlayerFromCharacter(hit.Parent) -- a useful method to get the player if player then local specialKey = tostring(player.UserId) -- I prefer the userid if not playerDebounceList[specialKey] then -- checking for debounce playerDebounceList[specialKey] = true -- placing them in the table for debounce -- do your code here else wait(1) -- waiting and then removing them from the list playerDebounceList[specialKey] = nil end end end end
The main issue with your code is that table.insert
places the item at a numeric index at the end of the table if no index is specified. Also, when you did your checking, you were checking for the player's name as an index when it was really a value in the table.