ModuleScript & Normal script require()

I don’t know if I’m doing this wrong or better way to do this but I’m getting errors.

image

Script

-- Administration In Admin

local module = require(script.Parent.Settings)

local AdminList = module.Admins()

local BanList = module.Bans()

local BanReason = module.BanMsg()

local MusicList = module.Music()

local BanAppeal = " | Appeal Appeal at are group wall why should be un-banned"

local IsAdmin = false

local IsBanned = false

-- IsAdmin()

game.Players.PlayerAdded:connect(function(player)

for _, v in pairs(module.Admins()) do

if player.UserId == v then

IsAdmin = true

print("RS ADMIN | IsAdmin() = true")

end

end

for _, v in pairs(module.Bans()) do

if player.UserId == v then

player:Kick(BanReason,BanAppeal)

IsBanned = true

print("RS ADMIN | IsBanned() = true")

end

end

end)

-- IsBanned()

Module

local module = {}
 function module.Admins()
	local adminlist = {1,12,744482898} -- UserID List of players that have admin
end
function module.Bans()
	local banlist = {744482898} -- UserID List of players want banned
end
function module.BanMsg()
 local banmsg = "You have been banned" -- Custom ban message
end
function module.Music()
	local music = {1234567,098765} -- Music List
end
return module

module.Admins() is a function with a table, however it doesn’t return the table.
Same with module.Bans() and the other funcs
I recommend doing:

local module = {}
 function module.Admins()
	local adminlist = {1,12,744482898} -- UserID List of players that have admin
        return adminlist
end
function module.Bans()
	local banlist = {744482898} -- UserID List of players want banned
        return banlist
end
function module.BanMsg()
 local banmsg = "You have been banned" -- Custom ban message
 return banmsg
end
function module.Music()
	local music = {1234567,098765} -- Music List
        return music
end
return module
3 Likes

Works, Thank you alot! I’m closing the post of now since it has been fixed. thanks.

1 Like

Better yet, just get rid of the functions, the module can be grinded down to pure data. The script can be kept the same, just merge the tables.

local module = {}

module.Admins = {1,12,744482898}
-- etc.

return module

This allows you to keep your code base while having it work as intended. You’ll just have to change some names around in both scripts respectively. Function calls are unnecessary here and so is the memory allocation done by table construction every call. I’d dare call it bad practice and inefficient code.

6 Likes