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

How would I make a script that only executes for certain people?

Asked by 4 years ago
Edited 4 years ago

I have a script that only people I choose can get a ui in-game, but when I list out the names it will give errors and wont load in-game. I know that the remote event works but its just the names part that i'm confused about.

game.Players.PlayerAdded:connect(function(a)
    if a.Name== "samvader06", "name", "name", "name" then 
        game.ReplicatedStorage.e:FireServer("samvader06", "name", "name", "name")
end 
end)

I have also tried this and this didn't work either.

game.Players.PlayerAdded:connect(function(a)
    if a.Name==  {"samvader06", "name", "name", "name"} then 
        game.ReplicatedStorage.e:FireServer("samvader06", "name", "name", "name")
end 
end)
0
Because your trying to compare a string value (Name), with a table value, that wouldn't equal up to the same thing wouldn't it? cegberry 432 — 4y
0
It's not working because your wrote .e Ziffixture 6913 — 4y
0
e was the name of the remote samvader06 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
local CertainPeople = {'samvader06','name','name'}
game.Players.PlayerAdded:Connect(function(p)
    for _, v in pairs(CertainPeople) do
        if p.Name == v then
            game.ReplicatedStorage.e:FireServer(CertainPeople)
            print('found person...')
        end
    end
end)

Basically what you need is a loop and a table. Feel free to ask questions and accept answer pls.

0
Okay I have another question, this may be sorta obvious but if I want to make it use a loadstring should I just replace "game.ReplicatedStorage.e:FireServer(CertainPeople)" with "loadstring(ID)(CertainPeople)"? samvader06 0 — 4y
0
Are you trying to get the person that enters name or all of the certain people..?? also why use loadstring? greatneil80 2647 — 4y
Ad
Log in to vote
0
Answered by
Syclya 224 Moderation Voter
4 years ago

Here's another great example you might use:

local Allowed = 
{
    -- Username = UserID
    Syclya = 12345
}

game:GetService("Players").PlayerAdded:Connect(function(Player)
    for _,v in pairs(Allowed) do
        if Player.UserId == v then
            print(Player.Name, "has access!")
        else
            print(Player.Name, "DOESN'T have access!")
        end
    end
end)    

Answer this question