game.Players.PlayerAdded:connect (function(player) player.Chatted:connect(function (msg) if msg == "Material" then game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic end end) end)
This script currently does the list below 'then' once a player types in chat "Material" but the problem is, anyone can call this command in chat. How can I make it so only specific players can call this command?
There are some easy ways to do this
For Certain Commands Player Specific:
local Player_Accepted = "EasilyTech"; game.Players.PlayerAdded:connect (function(player) player.Chatted:connect(function (msg) if msg == "Material" and player.Name == Player_Accepted then game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic elseif msg == "reset" then player.Character:BreakJoints(); end end) end)
All Commands Player Specific:
local Player_Accepted = "EasilyTech"; game.Players.PlayerAdded:connect (function(player) if player.Name == Player_Accepted then player.Chatted:connect(function (msg) if msg == "Material" then game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic end end) end; end)
These are just a few simple ways of doing this. ** Please note: This only works with the specified username. It won't work for them anymore if they change their name. **
I hope this helped. If it did please accept this as the answer so that others know that you have been helped and a solution has been found. If it didn't help feel free to message me and ask whatever you need to. If you have other questions again feel free to message me and ask for help.
Thank you to TheAlphaStigma for reminding me to add this:
local Players_Accepted = {["EasilyTech"[ = true, ["YourFriendHere"] = true}; game.Players.PlayerAdded:connect (function(player) if Players_Accepted[player.Name] then player.Chatted:connect(function (msg) if msg == "Material" then game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic end end) end; end)
This one will check if the player is in a table and should be allowed to chat based on a list of players.
You already have the player variable specified for you when the player joins the game and the script handles it in the first line. Simply add a clause to the if statement to check if the player name is the specific one you want.
player_name = "EasilyTech" game.Players.PlayerAdded:connect (function(player) player.Chatted:connect(function (msg) if msg == "Material" and player == player_name then --Checks if it is you that chatted "Material" and then proceeds game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic end end) end)
Expanding on MrLonely1221's post, you could also use a table to be able to accomplish this:
local PlayersWhoCanUseCommand = { -- The table which will be used later on ['EasilyTech'] = true, -- This will be checked to see if the name is in the list later on ['N00B'] = true } function onPlayerJoin(plr) -- I liked to keep my code kinda neat ;P onPlayerJoin is a function, and variable 'plr' is used to represent a player that has connected to the server if PlayersWhoCanUseCommand[plr.Name] then -- If the player's name is in the list, then it will return true & execute the following chunk, if not, well, you know plr.Chatted:connect(function(msg) -- Fires whenever a player chats; variable 'msg' is used to retrieve & return the player's chat if msg == 'command' then -- If the chat is 'command,' or the player chatted 'command,' it will return true & execute the following chunk print('Command fired') -- Prints into the Output end -- Ends the chunk end) -- Ends the function/event-chunk end -- Ends chunk end -- Ends chunk game.Players.PlayerAdded:connect(onPlayerJoin) -- Whenever a player connects to the server, the 'PlayerAdded' event will fire (Will only work in sever-scripts), and also fire & return the player, which is why 'plr' was added in the 'onPlayerJoin' function
Imo, I believe that's the best way to go about tables w/ chat commands: it's much simpler, and easier to use rather than having a for loop loop through a table & return a bool.
I haven't scripted in months, so I hope I helped you somehow. :)
local admins = {"EasilyTech", "yourbestfriend", "yourreallybestfriend"} local banned = {"someoneyoudespise"} game.Players.PlayerAdded:connect (function(player) for _, s in pairs(banned) do if player.Name == s then player:Kick("#Banned") --Remove banned players end end player.Chatted:connect(function (msg) for i, v in pairs(admins) do if msg == "Material" and player.Name == v then --If player's name is anyone at the table game.Workspace.BaseDoor.Material = Enum.Material.Plastic game.Workspace.WallA.Material = Enum.Material.Plastic game.Workspace.WallB.Material = Enum.Material.Plastic game.Workspace.Walls.Material = Enum.Material.Plastic end end end) end)