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

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

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)

3 comments

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?

0

It's not working because your wrote .e

0

e was the name of the remote

2 answers

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.

2 comments

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)"?

0

Are you trying to get the person that enters name or all of the certain people..?? also why use loadstring?

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)	

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