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
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
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.
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
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)
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?
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