Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

3 comments

0

depends what can he activate?

0

and when?

0

and what's the localscript?

2 answers

✓ Accepted answer

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

6 comments

0

but of course if you have any problem with it please let me know.

0

GG, works perfectly

0

Not work... work only the first ID

0

Hello check your new post :D

0

this could easily be changed by an exploiter so security-wise this is not the way to do it.

0

dude it's a localscript if an exploiter wants to exploit it he will lmao

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.