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

How do I whitelist add a player to a table in this admin script?

I'm trying to make a command where it will whitelist and add the player of the name I typed in into the table of whitelists. However, it's not adding them.

local settings = { whitelist = {"PLAYER1", "PLAYER2"}, prefix = ";" }
local prefix = settings.prefix
local plrs = game:GetService("Players") 
local plr = plrs.LocalPlayer 

this part of the code shows the settings which has the whitelist table and i want to extend it when i do the whitelist command but it doesn't work.

elseif cht:match(prefix .. "whitelist") then
local target = plrs[cht:sub(12)]
table.insert(settings.whitelist, target)

heres the part where i Try to table insert the targets name into the whitelist table. Any way to fix this? (I only showed the parts of the scripts that are affecting the names being added, everything else works proper so the target and etc is already made)

Basically, what do I put in the table.insert for me to add the targets name into the whitelist?

1 answer

Hello, you can use string.split() for it, try using this code:

plrs.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg) -- Their message
        local splitMsg = string.split(msg, " ") -- Splits their message into table
        local target = game.Players:FindFirstChild(splitMsg[2]) -- The player name '{;whitelist, juicevvrId}'
    end)
end)

Also, note that you can't never get the player by using LocalPlayer on a Script, it's only used on LocalScript. In order to get it, you have to use the PlayerAdded event.

2 comments

0

Not quite sure how I would use this, my code is like elseif cht:match(prefix .. "whitelist") then (it would table insert their name but it just doesn't work) I don't know how I'd put this into my script with it also working with my ";" prefix. and yes its a localscript

0

Then use a script inserted in ServerScriptStorage, because you can't get chatted Event on local script.

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