I’m still working on an arrests/citations database. I’ve been debugging my GUI code, and it appears to error (silently, there’s no output about it) at this line. databaseFE.GetArrestData:InvokeServer(lookup,"GetArrestRecordAmount")
It’s being invoked from the GUI inside the PlayerGui.
This is the code from databaseFE, which is a server script in ReplicatedStorage:
local databaseModule = require(script.Parent.DatabaseModule)
function script.GetArrestData.OnServerInvoke(plr,lookup,event)
if event == "GetArrestRecords" then
return databaseModule.GetArrestRecords(lookup)
elseif event == "GetArrestRecordAmount" then
return #databaseModule.GetArrestRecords(lookup)
end
end
And here’s the relevant code from databaseModule, a module script also in ReplicatedStorage:
local database = {}
local arrestsDS = game:GetService("DataStoreService"):GetDataStore("Database","Arrests")
local keyprefix = "lcrecordid_"
-- retrieve the arrest records for the given player
function database.GetArrestRecords(plr)
local key = keyprefix..plr.userId
local record = arrestsDS:GetAsync(key)
if record then
return record
else
return {}
end
end
Can anyone help me understand why the InvokeServer() is silently erroring?
Another issue could be an unhandled case. This is typically why you return at the end of an invoke, or any callback function, to ensure that something gets returned and doesn’t silently error or hang a script. The return at the end should be a default value or a nil to indicate that nothing could be returned.
local databaseModule = require(script.Parent.DatabaseModule)
function script.GetArrestData.OnServerInvoke(plr, lookup, event)
if event == "GetArrestRecords" then
return databaseModule.GetArrestRecords(lookup)
elseif event == "GetArrestRecordAmount" then
return #databaseModule.GetArrestRecords(lookup
end
return nil
end
Another error aside from your ServerScript not being in ServerScriptService (or even workspace for that matter) is that I think you may be calling an invoke wrong.
Invokes are supposed to be called like this (from my knowledge)
remotefunc.OnServerInvoke = function(player, blah, blah, blah)
--code
end
I had something just like this happening to me not too long ago. Aside from doing what colbert said, what fixed it for me was putting the RemoteFunction itself in ReplicatedStorage. For some reason, there would be no error but nothing would happen if the RemoteFunction was in some place like ReplicatedFirst.
Oh - that makes sense now! I was told server scripts won’t run in ReplicatedStorage, so do you have any suggestions as to where I should put the DatabaseFE script?
The script should go in ServerScriptService, the RemoteFunction should go in ReplicatedStorage. DatabaseModule should probably go in ServerStorage since the client won’t need it.
The issue is that for some reason the server is failing to return a value, so the LocalScript is left waiting forever. Looking at it right now, the only thing I can think of is that “DatabaseFE” isn’t properly setting the callback for “GetArrestData.” Did you change function script.GetArrestData.OnServerInvoke to function game:GetService("ReplicatedStorage").GetArrestData.OnServerInvoke?
(Also sorry for taking so long to respond, for some reason I wasn’t notified that you responded.)