Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why cant you ask if something is not inside of a table.. im frustrated?

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)

3 comments

0

you can do that...that returns false if hit.Parent.Name is in the table

0

If I helped you out, please accept my answer.

0

If not, comment under it and tell me what I can fix to help you better.

1 answer

✓ Accepted answer

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.

4 comments

0

That wouldn't be an array, it would be a dictionary.

0

whats the difference?

0

dictionary[key] = value; array[index] = value

0

Lua supports string indices. That is really a table, but I called it array because table is a keyword in Lua.

This discussion is preserved as it was. New answers, comments, and votes are closed.