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?
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
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.