I would, except line 2 of the module script is literally just “–Variables”
If you mean of the Parent Script, it’s require(script.adminCommands)
Oh ok I forgot that the error came form the script mb
would putting
local module = {}
at the top, and
return module ={}
at the end of your module make any changes?
I recall getting this error a while back.
Are you returning some type of value from the module? Or do you think you are returning more than one value?
I am returning the table, which holds the functions and commands from the module, but in theory it should work.
As long as your returning one thing, it should work, whether if it is a table, bool, string etc. etc.
Could you post your code? The error resides in the ModuleScript if the requiring script is throwing an error on require.
I would but I just tried and it failed. Miserably failed.
What do you mean? Ctrl + A, Ctrl + C, start a code block and post inside of it.
Ah, there we go.
--Variables
local m = {}
local Datastore = game:GetService("DataStoreService")
--Functions
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg,r)
if r then return end
end)
end)
--Table stuff
m.database = Datastore:GetDataStore("CoolAdminCommands")
m.adminList = {
41353321;
-1;
}
m.commandStart=":"
--Checking stuff
local List
pcall(function()
m.database:GetASync("adminList")
end)
if not List then
m.database:SetAsync("adminList", m.adminList)
List = m.adminList
end
--Doing some more stuff
function m.parse(msg,player)
local playerIsAdmin
for a,b in pairs(List) do
playerIsAdmin=b==player.UserId
if playerIsAdmin then break end
end
if playerIsAdmin then
if msg:sub(1,1)==m.commandStart then
if #msg==1 then
print("Just command start you silly goose")
else
local line = msg:sub(2,#msg)
local command, arguments = nil,{}
for a in line:gmatch("[%w%p]+") do
if command == nil then command = a else table.insert(arguments,a)
end
if m.commands[command] then
m.commands[command](arguments,player)
else
print("No command titled"..command.."exists")
end
end
end
end
end
end
m.commands = {
addAdmin = function(arg,caller)
for a,b in pairs(arg) do
if tonumber(b) then
print("Added admin"..b)
table.insert(List,tonumber(b))
m.database:SetAsync("adminList", List)
else
local userid = game.Players:GetUserIdFromNameAsync()
if userid then
print("Added admin"..b)
table.insert(List,userid)
m.database:SetAsync("adminList",List)
else
m.warn("addAdmin", "Player name \""..b.."\" is not a valid player")
end
end
end
end;
removeAdmin=function(arg,caller)
for a,b in pairs(arg) do
if tonumber(b) then
print("Added admin"..b)
for d,c in pairs(List) do
if c == tonumber(b) then
table.remove(List,d)
break
end
end
m.database:SetAsync("adminList",List)
else
local userid = game.Players:GetUserIdFromNameAsync()
if userid then
for d,c in pairs(List) do
if c == userid then
table.remove(List,d)
break
end
end
m.database:SetAsync("adminList",List)
else
m.warn("addAdmin", "Player name \""..b.."\" is not a valid player")
end
end
end
end;
print=function(arg,caller)
for a,b in pairs(arg) do
print(b)
end
end
}
--Even more stuff
function m.warn(cmd, issue)
print("In command "..m.commandStart..cmd.." issue occured, receipt: "..issue)
end
return m
The issue is somewhere at the top of your script. I threw this code raw into a new place file and tried running it; surely enough, I got the same error. After I began to add prints to the code to set up a form of benchmarks, I noticed that some of the prints were not running. Specifically at the top.
Note: there were a few spelling and conventional mistakes, which I corrected.
The code within the blue square is where the issue is occurring. I haven’t worked towards a solution regarding this chunk yet, though something here is not going as intended. Precisely, it’s refusing to even enter beyond the SetAsync statement.
Seems like you have a bit of a spelling issue here.
Corrected:
m.database:GetAsync("adminList") -- Line 25
That’s a non-problem. OP would’ve caught that in the Developer Console if they printed out the error message - the “GetASync is not a valid member of GlobalDataStore” is not being thrown because it’s wrapped in a pcall. The issue is specifically with the SetAsync statement below it.
Oh wow, nice spot!
However, this sadly isn’t the only issue. It seems there are a couple more errors further down in the script (This can be seen because of colbert’s print debugging).
@colbert2677 please keep in mind that you would need to GetAsync
before SetAsync
, and with an error in GetAsync
, how will SetAsync
work correctly?
What are you talking about? You do not need to run GetAsync before you do SetAsync. Getters and setters are two different functionalities altogether and are not dependent on one another. GetAsync returns a value from the key you specify. Set enforces a value to a key. Just because GetAsync errors, that doesn’t mean the same will happen for SetAsync.
Okay, I think I might’ve figured out the flaw regarding this script. I tried running a unit test again, since my first run was flawed. Just as my suspicions confirmed, I went and refurbished the pcall statement - the error is in the SetAsync method. Though this unit test was a little different.
I simply toggled this. OP… do you have this enabled? You can’t use DataStores in Roblox Studio without this enabled. I toggled it and I received no errors at all.
It seems I have maybe goofed up.
Thank you for pointing out the API activation… I am now a “prize plonker”.
Once again, thank you so much for pointing this out.
Remember that in the future, anything that’s internally a web call (such as DataStores), you’ll want to wrap in pcalls due to their potential to error. Since you already seem to be doing that, make sure you make the most out of pcalls by making use of its return values for debugging purposes; the success bool and the results of a pcall.
Truthfully I didn’t understand the issue but after figuring out that nothing was wrong with your code, I knew there was an external issue. It was only until I modified your GetAsync pcall that I figured out what was happening.
local success, result = pcall(function ()
return GetAsyncStatement
end) -- If it succeeds, returns GetAsync value, otherwise an error
print(success, result) --> false & HTTP 500-code regarding unauthorised access
Alright, thanks for the advice.