As the title says, How do I check all players if their userId is the same as the one in the list, and give them specifically a admin panel?
Here is my current script:
local Players = game:GetService("Players")
local AdminIds = {1545243842, 809620631} -- 1545243842 is Quif and 809620631 is the Owner
for _, v in pairs(Players:GetPlayers()) do
if table.find(AdminIds,v.UserId) then
-- dont know what to put here
end
end
Always check the UserId on the Server, not the client, because it will be vulnerable to exploits.
Client-Side code:
-- Create a RemoteEvent
local CheckUserID = Instance.new("RemoteEvent")
CheckUserID.Parent = game.ReplicatedStorage
CheckUserID.Name = CheckUserID
-- Fire the RemoteEvent
CheckUserID:FireServer()
-- Returns true if matches one of the UserId's
CheckUserID.OnClientEvent:Connect(function(trueornot)
if trueornot == true then
--Show Admin Panel Here
end
end)
Server-Side:
local CheckUserID = game.ReplicatedStorage.CheckUserID
CheckUserID.OnServerEvent:Connect(function(plr)
if plr.UserId == 1545243842 or plr.UserId == 809620631 then
CheckUserID:FireClient(plr, true)
else
CheckUserID:FireClient(plr, false)
end
end)
I’d recommend not using a For loop for checking all the players because this will run as the server starts.
You may wanna consider trying the following code:
local Players = game:GetService("Players")
local AdminIds = {1545243842, 809620631} -- 1545243842 is Quif and 809620631 is the Owner
Players.PlayerAdded:Connect(function(Player)
if not table.find(AdminIds, Player.UserId) then return end
script:FindFirstChild("AdminGui") and script:FindFirstChild("AdminGui"):Clone().Parent = Player:WaitForChild("PlayerGui")
end)
--// Ofcourse put this script inside ServerScriptService and the Gui inside it, And make sure it named "AdminGui".