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

How i can create an access to a LocalScript for certain people?

Asked by 4 years ago

Hi, sorry for bad english

I have a LocalScript with my script inside, but only certain player can use it! Like this:

ALLOWED_ACCESS = {
    [myid] = true,
    [myfriendid] = true,
    [blablaid] = true, 
}

This need to be inside the LocalScript, and if the name is inside the "ALLOWED_ACCESS", the Player can activate the LocalScript

Exist a method to do it?

0
depends what can he activate? VitroxVox 884 — 4y
0
and when? VitroxVox 884 — 4y
0
and what's the localscript? VitroxVox 884 — 4y

2 answers

Log in to vote
1
Answered by
VitroxVox 884 Moderation Voter
4 years ago
Edited 4 years ago

Well i don't really understand what you wanted cause i'm missing some information about it but i can show you an example script with that method:

ALLOWED_ACCESS = {
[myid] = true,
[friendsid] = true, 
[blablaid] = true,
}

function checkifallowed(userid)
    for ids,allowed in pairs(ALLOWED_ACCESS) do
        if ids == userid and allowed then
            return true
        else
            return false
        end
    end
end

wait(5)

if checkifallowed(game.Players.LocalPlayer.UserId) then
    print("YASS I'M ALLOWED :3")
else
    print("cri im not allowed ;((")
end

BUT HEAR ME OUT

There's an easier way to do this:

ALLOWED_ACCESS = {myfriendsid,myid,blalaid,blalaid,ucankeeponaddingids}

function checkifallowed(userid)
    for _,allowed in pairs(ALLOWED_ACCESS) do
        if allowed == userid then
            return true
        else
            return false
        end
    end
end

wait(5)

if checkifallowed(game.Players.LocalPlayer.UserId) then
    print("ok cool i'm allowed :D")
else
    print("cri im not allowed :(")
end

if it worked please accept, thank you

0
but of course if you have any problem with it please let me know. VitroxVox 884 — 4y
0
GG, works perfectly GuerraReturns 122 — 4y
0
Not work... work only the first ID GuerraReturns 122 — 4y
0
Hello check your new post :D VitroxVox 884 — 4y
View all comments (2 more)
0
this could easily be changed by an exploiter so security-wise this is not the way to do it. profak 15 — 4y
0
dude it's a localscript if an exploiter wants to exploit it he will lmao VitroxVox 884 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Since you made your whitelist a dictionary, you don't need the loop.

This:

ALLOWED_ACCESS = {
[myid] = true,
[friendsid] = true, 
[blablaid] = true,
}

function checkifallowed(userid)
    for ids,allowed in pairs(ALLOWED_ACCESS) do
        if ids == userid and allowed then
            return true
        else
            return false
        end
    end
end

Can just be this:

ALLOWED_ACCESS = {
[myid] = true,
[friendsid] = true, 
[blablaid] = true,
}

function checkifallowed(userid)
    return ALLOWED_ACCESS[userid] or false
end

The or false is optional, but it's a good habit to return true or false rather than true or nil when a boolean is expected, so that if you were to print it or compare to false it would work as expected. That said, even having a function wrap this dictionary is probably unnecessary if it's only called from within this same script. If it were part of an API exposed from a module to other scripts, you'd want this to stay a function.

Answer this question