Why does this whitelist table not work?

Hello,

I am trying to make some of my friends and I whitelisted to a command that refreshes your character; Problem is, when I try to use the command, it does not work at all; Even though my name is in the whitelisted table.

Here’s the Local Script:

local whitelistedPeople = {"hasoco","zjkaleemsecondAlt","Player1","Player2","BuiIdYourCreation","Thunder_Alex12"}
plr.Chatted:Connect(function(msg)
	local sp = string.split(msg," ")
	if whitelistedPeople[plr.Name] then
		if ARGS[1] == sp[1] then
			print("Prefix chatted.")
			if ARGS[2] == sp[2] then
				print("2/3 command.")
				if sp[3] then
					local tplr = game.Players[sp[3]]
					if tplr then
						RefreshEvent:FireServer(sp[3])
					end
				end
			end
		end
	end
end)

To search a table use table.find

local whitelistedPeople = {"hasoco","zjkaleemsecondAlt","Player1","Player2","BuiIdYourCreation","Thunder_Alex12"}
plr.Chatted:Connect(function(msg)
	local sp = string.split(msg," ")
	if table.find(whitelistedPeople, plr.Name) then
		if ARGS[1] == sp[1] then
			print("Prefix chatted.")
			if ARGS[2] == sp[2] then
				print("2/3 command.")
				if sp[3] then
					local tplr = game.Players[sp[3]]
					if tplr then
						RefreshEvent:FireServer(sp[3])
					end
				end
			end
		end
	end
end)

Can I ask, why doesn’t whitelistedPeople[plr.Name] work?

This is the way to look up in dictionaries, for the table to work, it must look like this

local whitelistedPeople = {
	["hasoco"] = true,
	["zjkaleemsecondAlt"] = true,
	["Player1"] = true,
	["Player2"] = true,
	["BuiIdYourCreation"] = true,
	["Thunder_Alex12"] = true
}

It will return true if the name is in the dictionary, otherwise it will be nil.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.