Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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
0
Thanks, it worked. How would I make a command that would add a player to that whitelist, like ;whitelist PLAYER3 TunaComic -3 — 3y
0
Write: table.insert(settings.whitelist, "PLAYER3") Shounak123 461 — 3y
Ad

Answer this question