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

Why is my script not recognizing peoples user ids?

I am currently working on an admin GUI, which is cloned from ServerStorage to a player PlayerGui if they have a certain UserId. So far, it does clone the right GUI into the player's PlayerGui, however, when a player in the "Lesser admin" category decides to press a certain key to open the GUI, nothing comes up. What is the problem here?

Server Script: (To clone the GUI into the players PlayerGui)

adminIDS = {72372728, 74518383, 21588477, 1224291081}
lesserAdminIDs = {44667224, 1588609025, 1679275868}

local function checkIfAdmin(player)
	local find = table.find(adminIDS, player.UserId)
	if find ~= nil then
		return true
	else
		return false
	end
end

local function checkIfLesserAdmin(player)
	local find = table.find(lesserAdminIDs, player.UserId)
	if find ~= nil then
		return true
	else
		return false
	end
end

game.Players.PlayerAdded:Connect(function(player)
	if checkIfLesserAdmin(player) then
		local askAdmin = game.ServerStorage.AskAdmin:Clone()
		askAdmin.Parent = player:FindFirstChild("PlayerGui")
	end
	
	if checkIfAdmin(player) then
		local list = game.ServerStorage.BanList:Clone()
		local askAdmin = game.ServerStorage.AskAdmin:Clone()
		list.Parent = player:FindFirstChild("PlayerGui")
		askAdmin.Parent = player:FindFirstChild("PlayerGui")
	end
end)adminIDS = {72372728, 74518383, 21588477, 1224291081}
lesserAdminIDs = {44667224, 1588609025, 1679275868}

local function checkIfAdmin(player)
	local find = table.find(adminIDS, player.UserId)
	if find ~= nil then
		return true
	else
		return false
	end
end

local function checkIfLesserAdmin(player)
	local find = table.find(lesserAdminIDs, player.UserId)
	if find ~= nil then
		return true
	else
		return false
	end
end

game.Players.PlayerAdded:Connect(function(player)
	if checkIfLesserAdmin(player) then
		local askAdmin = game.ServerStorage.AskAdmin:Clone()
		askAdmin.Parent = player:FindFirstChild("PlayerGui")
	end
	
	if checkIfAdmin(player) then
		local list = game.ServerStorage.BanList:Clone()
		local askAdmin = game.ServerStorage.AskAdmin:Clone()
		list.Parent = player:FindFirstChild("PlayerGui")
		askAdmin.Parent = player:FindFirstChild("PlayerGui")
	end
end)

Local Script: (To check if the GUI is in PlayerGui)

player = game.Players.LocalPlayer
mouse = player:GetMouse()
askAdmin = player:WaitForChild("PlayerGui"):WaitForChild("AskAdmin")
banList = player:WaitForChild("PlayerGui"):WaitForChild("BanList")
enabled = false
otherEnabled = false

local function makeAllInvisible(gui)
	local children = gui:GetChildren()
	for i = 1, #children do
		children[i].Visible = false
	end
end

mouse.KeyDown:Connect(function(key)
	if key:lower() == "z" then
		if player:FindFirstChild("PlayerGui"):FindFirstChild("AskAdmin") ~= nil then
			otherEnabled = not otherEnabled
			if otherEnabled then
				askAdmin:WaitForChild("Players").Visible = true
			else
				makeAllInvisible(askAdmin)
			end
		end
	end
	
	if key:lower() == "x" then
		if player:FindFirstChild("PlayerGui"):FindFirstChild("BanList") ~= nil then
			enabled = not enabled
			if enabled then
				banList:WaitForChild("Banned").Visible = true
				banList:WaitForChild("Search").Visible = true
			else
				makeAllInvisible(banList)
			end
		end
	end
end)

1 answer

You could just say:

if adminIDS[player.UserId] == true then
    --Do stuff
end

4 comments

0

But doesn't table.find work the same?

0

Also like I mentioned earlier, the server script already recognizes any rank of admin, its the local script thats the problem I think, since I checked console and the admins already have the GUI in their PlayerGui.

0

This is easier tho, and prevents a lot of bugs.

0

your way actually doesnt work, its not a dictionary, its an array, its key is not player.UserId

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