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

Module script list not working how i would like?

What i need is if the players name is on of the admins the gui will be enabled and else it is not enabled. Please help

Local Script


local o = script.Parent.o
local mod1 = require(game.ServerScriptService.Admins)


o.Activated:Connect(function()
	script.Parent.Parent.AdminGUI.Enabled = true
	script.Parent.Enabled = false
end)

if script.Parent.Parent.Parent.Name == mod1.Admins then
	script.Parent.Enabled = true
else
	script.Parent.Enabled = false
end

Module

local module = {}

--List admins below how i listed them.

module.Admins = {
	"Plieax",
	"X_ack",
	"Player1",	
	}
return module

2 comments

0

You should not be messing around with guis from the server. Use a LocalScript.

0

Oh you meant to say Local lol

2 answers

✓ Accepted answer

You can use LocalPlayer to get the player. Here is how:

local players = game:GetService("Players")
local plr = players.LocalPlayer
-- The problem is you are checking the players name against the table. That wont work
--here is a function I did to fix that:
local function isAdmin(plr)
	
	for i,v in pairs(admins) do -- looping through the table
		
		if v == plr.Name then
			
			return true
		
		end
		
	end
	
	return false -- if the name never matches then return false
	
end
-- then just check
if isAdmin(plr) then
end

Hope this helps and have a great day scripting!

3 comments

1

You should also mention that ServerScriptService is inaccessible by clients, OP attempted to access it via a LocalScript

0

Oh yeah. Sorry.

0

You might want to input UserId's instead of names because players can change their usernames.

First of all, you are trying to require a module placed in ServerScriptService from a LocalScript!! That will only work in studio and will NOT work once you publish the game.

You could probably place the module somewhere else, such as ReplicatedStorage, however then exploiters will be able to view your admin list.

If you would like to prevent that, you should probably clone the gui to the player's PlayerGui using a server-script, like this:

Server script:

local AdminGui = game.ServerStorage.AdminGUI
local Admins = {
	["Someone123"] = true,
	["Someone else"] = true
}

game.Players.PlayerAdded:Connect(function(plr)
	if Admins[plr.Name] then
		plr.CharacterAdded:Connect(function()
			AdminGui:Clone().Parent = plr:WaitForChild("PlayerGui")
		end)
	end
end)

Or if you still want to do this from the LocalScript, place the Admins module somewhere else and do what @Phlegethon5778 suggested.

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