How to fix "Unknown require"?

im really not sure, ive tried editing the code a bit but i dont know what to do
i also dont really know how to use module scripts but thought i’d try

heres the script that has the require

local bannedIds = require(game.ReplicatedStorage.BannedGears)
script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr, tool)
	
	local insert = game:GetService("InsertService"):LoadAsset(tool):FindFirstChildWhichIsA("Tool")
	insert.Parent = plr.Backpack
	print(plr.Name .. " has been given asset id " .. tool .. ", the name of the tool is " .. insert.Name)
end)

and heres the module which is probably the problem


local bannedGears = {}

local bannedIds = {
	88885539;
	268586231;
	90718350;
	117498775;
	68354832;
	78730532;
	94794833;
	94794774;
	86494893

}

function bannedGears.checkGears(id)
	for i, v in pairs (bannedIds) do
		if v == id then
			return id, true
		else
			return id, false
		end
	end
end

return bannedGears

if anyone can help me please let me know the issue

1 Like

If the error you’re getting is on the same line as:

local bannedIds = require(game.ReplicatedStorage.BannedGears)

You might want to add a :WaitForChild()

local bannedIds = require(game.ReplicatedStorage:WaitForChild("BannedGears"))

This makes it so that if BannedGears isn’t loaded in yet, the script will have to wait for it to be added into the game before moving on to the next lines of code

its not an error from the output its more of when i hover my mouse over that line it says unknown require then the location

That’s strange, could you reply with a screenshot of what you mean? Also, if you can, could you also post a screenshot of your script’s hierarchy (the explorer)? The unknown require could be due to you trying to reference the ModuleScript that’s in a different area.

Ex: The ModuleScript could be in ServerStorage, but the script is trying to find the ModuleScript in ReplicatedStorage.

Seems like this is related to your issue

of course, i did end up putting the banned ids in the actually script itself but hopefully i can get the module working

Could you send a screenshot of your explorer? I’m not getting that error and I copied and pasted your scripts

Also, for future reference don’t put a server script in ReplicatedStorage, I was just doing it as an example lol

Explorer:

  • image

Server Script:


Module Script:

  • image

I searched online a little bit, on the documentation and found this (maybe you returned the wrong value in your ModuleScript?):


Furthermore, if I comment out the ModuleScript’s return value, it prompts me with the error you had

alright, ill send it bit by bit because there is alot in different locations

actually just have the whole thing (except unneccesary stuff)

1 Like

Oh, I didn’t mean your entire explorer - I meant just the locations where the original script, ModuleScript and RemoteEvent are

1 Like

i changed the image because i didnt include replicated storage

also some of the lines i provided above have also changed

Oh ok that’s why I was a little confused lol, could you send the screenshots of the new ModuleScript and GiveGear code? I just want to verify the ModuleScript has a proper return value

alright
the only change was the serverscript

local bannedIds = {
	"88885539",
	"268586231",
	"90718350",
	"117498775",
	"68354832",
	"78730532",
	"94794833",
	"94794774",
	"86494893",
	--"93136746"
	--"95951291"
}

--local bannedIds = require(game.ReplicatedStorage.bannedGears)

game.ReplicatedStorage.GiveGear.OnServerEvent:Connect(function(plr, tool)
	local insert = game:GetService("InsertService"):LoadAsset(tool):FindFirstChildWhichIsA("Tool")
	if not table.find(bannedIds, tool) then
		insert.Parent = plr.Backpack
		print(plr.Name .. " has been given asset id " .. tool .. ", the name of the tool is " .. insert.Name)
	else
		insert:Destroy()
		print(plr.Name .. " has attempted to insert the banned asset id " .. tool .. ", the name of the banned tool is " .. insert.Name)
	end
end)

and locations of assets but those are provided in the screenshot

1 Like

Well, I mean there shouldn’t be a problem with this code- But I assume you want to use the ModuleScript. Since you said you’re new to ModuleScripts here’s what I suggest you to do:

Moving the bannedIds table into the ModuleScripts return value

Like so:

-- bannedGears ModuleScript

local bannedGears = {
	
	["bannedIds"] = {

		88885539,
		268586231,
		90718350,
		117498775,
		68354832,
		78730532,
		94794833,
		94794774,
		86494893,
		--93136746
		--95951291
	}
	
}

-- Functions and other module script code and stuff here...
-- You can reference bannedIds in this ModuleScript by using: bannedGears.bannedIds

return bannedGears

And you can import bannedIds in the GiveGear server script like so:

-- GiveGear server script

local bannedGears = require(game.ReplicatedStorage:WaitForChild("bannedGears"))
local bannedIds = bannedGears.bannedIds;

The only way I’ve been able to replicate the error you had at the beginning was to remove the ModuleScript’s return value:

return bannedGears -- This line here

Make sure you don’t remove that line ^ at the bottom (it should also be the last line in the ModuleScript)

Other than that, I can’t really help you further besides asking you to maybe restart studio?

alright!
ill attempt to insert this into my code and give it a try

1 Like

it actually works well, i am having a bit of trouble detecting if an id is in the table or not however

2 Likes

Well there’s a couple of different ways of detecting if an ID is in the table or not

You could index the table with the id and check if it is nil:

if bannedIds[PUT_ID_HERE] == nil then
-- Runs code if the ID does NOT exist in the table
end

or you could loop through the entire table and check if an id matches it (though the above method is much simpler):

local IsIDBanned = false;
for _, BannedID in pairs(bannedIds) do
    if tostring(BannedID) == tostring(PUT_ID_HERE) then 
       -- I used tostring() to make sure both values are the same type (string)
       IsIDBanned = true;
    end
end

if not IsIDBanned then
-- Runs code if ID does NOT exist in the table
end

Edit: also make sure to mark a reply as a solution to let others know you’ve solved the problem :+1:

perfect! i couldnt get your first method to work but the second method works well

1 Like