I’m trying to find out how to make my command private only for some users, although I’m not finding any articles or places that answer my question.
I tried searching up some tutorials, but didn’t find any in the DevForum or the DevHub. I tried searching other places, but couldn’t find any.
Here’s my code:
p=game.Workspace.Curtains
function onChatted(msg, speaker)
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "/e !?opencurt" then
for i=1,100 do
p.CFrame=p.CFrame+Vector3.new(0,0,-1)
wait()
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
On chatted speaker is a player. So you can check if they are an admin like this
if speaker.UserId == 1 or speaker.Name == "sloss2003" then
and then do something.
========================================
If you want to have an array of admin usernames you can do this
local admins = {"sloss2003"};
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
I would add it before your command checks like this
p=game.Workspace.Curtains
function onChatted(msg, speaker)
local source = string.lower(speaker.Name)
if source == "sloss2003" --[[your name here]]then
msg = string.lower(msg)
if msg == "/e !?opencurt" then
for i=1,100 do
p.CFrame=p.CFrame+Vector3.new(0,0,-1)
wait()
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
Why?
This way you can write more commands under it with ease, without having to copy and paste isAdmin(speaker) into each if-statement.
You can, it’ll make your life easier. You can do it like this:
local admins = {"sloss2003"}; -- put your admin names here
local p=game.Workspace.Curtains
function checkAdmin(speaker)
local isAdmin = false;
for a,b in pairs (admins) do
if b == speaker.Name then
isAdmin = true;
break;
end
end
return isAdmin
end
function onChatted(msg, speaker)
if checkAdmin(speaker) then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "/e !?opencurt" then
for i=1,100 do
p.CFrame=p.CFrame+Vector3.new(0,0,-1)
wait()
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)