How would I go about making this Teleport command whitelisted

I have this command, that if you click on a door, it teleports you to the interior of a house. But I want it to be only for me and my friends Roblox usernames (no group). How would I go about putting that in there?

local Clickness = script.Parent.ClickDetector

local Plyr = game.Players.LocalPlayer
local Remote = game.ReplicatedStorage.ScreenStuff.Fade
local Position = game.Workspace.Teleports.TurfEntrance
local using = false

Clickness.MouseClick:Connect(function(Player) 
	Remote:FireClient(Player)
	wait(2)
	Player.Character.Torso.CFrame = Position.CFrame
end)

Simply, just use an if statement:

if player.Name == yourname or player.Name == friendsname then
    -- do stuff
end
1 Like

I would use tables instead personally. It prevents a long line of every person to whitelist. Instead I would do something like this:


local Whitelist = {
	1234567890, --UserId of player to whitelist
	1234565432--Add more Ids to whitelist more players
}

local Clickness = script.Parent.ClickDetector

local Plyr = game.Players.LocalPlayer
local Remote = game.ReplicatedStorage.ScreenStuff.Fade
local Position = game.Workspace.Teleports.TurfEntrance
local using = false

Clickness.MouseClick:Connect(function(Player) 
	if table.find(Whitelist, Player.UserId) then  --Sees if the player who used the command is in the whitelist table
		Remote:FireClient(Player)
		wait(2)
		Player.Character.Torso.CFrame = Position.CFrame
	end
end)


2 Likes

I agree, tables would be more readable.

1 Like

Indeed tables are a much more readable way. If you plan on the table being large, I suggest you make it a dictionary as it will lower indexing time significantly.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.