Hello,
I just came across something while I was coding and I do not know how to implement it. So, I have a Module Script and what I want it to do is give permission to any userId mentioned in the Module Script.
local Users = require(game.ServerScriptService.ModuleScript)
if game.CreatorId == Users.User1 or Users.User2 then
print("Success!")
else
print("Failure")
end
Instead of having to type âorâ always, I want the script to take in any UserId in module script and accept it. Is it possible to do something like that?
local Users = require(game.ServerScriptService.ModuleScript)
for User, Id in pairs(Users) do
if game.CreatorId == Id then
print("Success!")
else
print("Failure")
end
end
@D0RYUâs code is telling you if each value within the array is the creatorâs ID or not. I would just recommend using table.find() as itâs a built in library to handle finding if a certain value exists in an array.
local module = {
creators = {
1792448898, -- User 1
1783349062 -- User 2
}
}
return module
This way, if you need to add or remove an accepted user, you can without needed to modify multiple files. To implement this for your code (i.e. Script), I would make a function called MadeByTeam() (or whatever you think makes sense) that will return a String (either "Success!" or "Failure").
local AcceptedCreators = require(game.ServerScriptService.ModuleScript)
function MadeByTeam()
-- Handles the case when the AcceptedCreators.creators list is empty
-- as otherwise the code would fail in that situation.
if (#AcceptedCreators.creators == 0) then
return "Failure"
end
for i = 1, #AcceptedCreators.creators do
if game.CreatorId == AcceptedCreators.creators[i] then
return "Success!"
end
end
return "Failure"
end
-- prints out either "Success!" or "Failure"
print(MadeByTeam())
The for loop checks if the gameâs creator is any of the accepted creators, and returns âSuccess!â if that is the case. If the loop has went through all of the accepted creators, and it hasnât returned anything yet, it means that the creator is not an accepted creator and thus the program will return âFailureâ.