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

How do I Fix invalid argument #2 (string expected, got table)?

Hi, I made a local admin script for one of my games and I'm trying to add a table for names who can be admin but it's giving me the error. Heres the 2 parts doing it but I'm not sure how to fix it.

local settings = { whitelist = {"PLAYER1", "PLAYER2"}, prefix = ";" }

local plrs = game:GetService("Players") local plr = plrs.LocalPlayer local whitelist = plrs[settings.whitelist] local prefix = settings.prefix

1 answer

✓ Accepted answer

You can do to get the players like this:

local settings = { whitelist = {"PLAYER1", "PLAYER2"}, prefix = ";" }

local plrs = game:GetService("Players") 
local plr = plrs.LocalPlayer 

for key, value in pairs(settings.whitelist) do
	for _, Player in pairs(plrs:GetChildren()) do
		if Player.Name == value then
			
			--You can write what you want to do to the player here.
			--Here, write "Player" for the player
			
		end
	end
end

local prefix = settings.prefix

2 comments

0

Thanks, it worked. How would I make a command that would add a player to that whitelist, like ;whitelist PLAYER3

0

Write: table.insert(settings.whitelist, "PLAYER3")

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