I made a script where it accepts a certain users inside the module scripts, otherwise, it deletes a part.
I tried many of the resources but they aren’t working as needed.
This is my script:
SCRIPT:
local UserModule = require(game.ServerScriptService.ModuleScript)
if game.CreatorId == table.find(UserModule, game.CreatorId) then
game.Workspace.Part.Anchored = true
else
game.Workspace.Part:Destroy()
end
Module Script
local module = {
1783349062
}
return module
Please tell me if there is any problem with it and how I can fix this issue.
you need to call the module with a function, you cant blank fire a module like that
module = {
module.GetIds()
return {1783349062} -- Add the other players
end
}
return module
-------------------------------
local UserModule = require(game.ServerScriptService.ModuleScript)
if game.CreatorId == table.find(UserModule.GetIds(), game.CreatorId) then
game.Workspace.Part.Anchored = true
else
game.Workspace.Part:Destroy()
end
A module itself is an array of functions, so when you require a module you are prompting the module script to return all of the functions it has. I’m surprised you didn’t get an error message just putting the numbers in there to be honest
local UserModule = require(game.ServerScriptService.ModuleScript)
if table.find(UserModule, game.CreatorId) then
game.Workspace.Part.Anchored = true
else
game.Workspace.Part:Destroy()
end
A module can contain a table of numbers and that on its own should be fine. You can also add functions to ModuleScripts. They can keep your code organized by containing functions that you often use. As long as the ModuleScript has return values and you’re requiring them properly, you shouldn’t have a problem. Try it out yourself on Roblox Studio.
Create a ModuleScript in ServerScriptService and put this inside.
return {1,2,3,4,5}
Create a Script and put this inside.
local UserModule = require(game.ServerScriptService.ModuleScript)
print(UserModule) -- You will see that the table prints out.
print(UserModule[1]) -- You will see that the first index in the table prints out.
Not necessary, a module does not have to contain a function. When require is called on it, if it is the first time, it runs the script and stores the returned result. If it is any subsequent time, it returns the same result. That allows you to have shared tables between scripts.