How to make a Admin List with Tables

Hello,

In this tutorial I will show you how to make a admin list with tables

This is my first tutorial so bear with me.


Lets Start!

I’m going to use a local script
I’ll be putting my script in StarterPlayerScripts. Then in ReplicatedStorage we want to add a RemoteEvent.

-- Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent
-- Now we fire the RemoteEvent
RemoteEvent:FireServer()

Now we add a script in ServerScriptService

-- Script
local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

We add a Table to the script like so

-- Script
local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

local Admins = { -- You can name "Admin" what ever you want
	

}

In are Table we add the userID of a player you want. Now we go to the Roblox Website and to the profile of the player you want to add. In you’re browser go to the ULR and theres numbers, thats the userID
Screenshot 2022-03-12 161745
And you’re script should look like this

local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

local Admins = { -- You can name "Admin" what ever you want

	1507646970 

}

If you want to add more players the Table then you should do this

local Admins = { -- You can name "Admin" what ever you want

	1507646970, -- Make sure that the last userID in the Table does not end with an ","
	3327692056

}

Now we add something that detects if the RemoteEvent fires

local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

local Admins = { -- You can name "Admin" what ever you want

		1507646970, -- Make sure that the last userID in the Table does not end with an ","
	    3327692056

}
-- Now this function fires when RemoteEvent Fires
RemoteEvent.OnServerEvent:Connect(function(player) -- We need to add "player" to the fuction

end)

Now inside the Function we and an If statement

local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

local Admins = { -- You can name "Admin" what ever you want

	1507646970

}
-- Now this function fires when RemoteEvent Fires
RemoteEvent.OnServerEvent:Connect(function(player) -- We need to add "player" to the fuction
	if not table.find(Admins, player.UserId) then
		return -- Returns if the player is not an Admin
	end
end)

Inside of the function statement we add print()

RemoteEvent.OnServerEvent:Connect(function(player) -- We need to add "player" to the fuction
	if not table.find(Admins, player) then
		print(player.Name.." is a Admin") -- If the player is an Admin
	else
	print(player.Name.." is an Admin")
end)

The Full scripts

Script

local Players = game:GetService("Players") -- Getting Players Service -- LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent

local Admins = { -- You can name "Admin" what ever you want

	1507646970

}
-- Now this function fires when RemoteEvent Fires
RemoteEvent.OnServerEvent:Connect(function(player) -- We need to add "player" to the fuction
	if not table.find(Admins, player.UserId) then
		return
	end
	print(player.Name.." is an Admin")
end)

LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Getting Replicated Storage Service
local RemoteEvent = ReplicatedStorage.RemoteEvent --Getting the RemoteEvent
-- Now we fire the RemoteEvent
RemoteEvent:FireServer()

You should get this output

Output

Thanks for the feedback

@lxbical @ValiantWind @Gojinhan @commitblue

:warning: Any scripts in the reply I didn’t test them

4 Likes

Have you taken into account in checking with the server? No. This is important because an exploiter could go and make themselves an admin by messing with your script, as shown in the client server model article mentioning serverside validation. You should always use the server in these sorts of cases.

If you were to improve this tutorial, you should probably take a read of this: Roblox Client-Server Model and then after make use of Remote Functions and Events.

Additionally, ‘tabels’ should be corrected to ‘tables’

9 Likes

The issue with your statement is that he is using the server to check all hes doing is on the remote being fired using the player argument that roblox passes to the function its a server side check with no way to get around it other than to have edit access

so where’s the part where he inserts a player’s userid into the table :face_with_raised_eyebrow:

I’m pretty sure RemoteEvents aren’t even needed for this since you can just use ModuleScripts.

1 Like

He has edited the post since i’ve made that statement to include validating from the server, sorry for any confusion

For the record, you don’t even need to fire a remote to say “hey please check if im admin”, instead you can just hook up that check to player added, e.g:

local players = game:GetService('Players')

local permission_map = {
    [3218743] = math.huge,
}

local function Check(player)
    local permission = permission_map[player.UserId]

    if permission then
         print('Player has special permissions!')
    end
end

for _, player in ipairs(players:GetPlayers()) do
    task.spawn(Check, player)
end

players.PlayerAdded:Connect(Check)

Personally I would also make a special gui in ServerStorage that has scripts under it to run when it’s parented. Once the player is confirmed to have special permissions, you can clone it, set the permission level, then finally parent it to the players playergui.

This should be a more flexible way of doing it that also doesn’t include an unnecessary remote call.

2 Likes

Sending a remote is pretty unnessecary since a function is made for this.

Game.players.playeradded.

2 Likes

You can do all of this on the server.

Here:

local Players = game:GetService("Players")

local admins = {}

local function IsAdmin(player)
     for _, v in pairs(admins) do
        if player.UserId == v then
            print(player.Name.." is an admin!")   
        else
        print(player.Name.." is not an admin!")     
        end
    end
end

Players.PlayerAdded:Connect(IsAdmin)
2 Likes