-
What do you want to achieve? Keep it simple and clear!
The client needs information regarding item codes and their corresponding data. I made a remote function that, when the server is invoked, is supposed to return a copy of the requested data. -
What is the issue? Include screenshots / videos if possible!
The remote function is returning ‘nil.’ -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
As seen in the code below, I’ve formatted the remote function correctly (as far as I’m aware). Someone mentioned checking if other scripts have callbacks. One script has a callback related to a different remote function. I tested disabling that callback. It still didn’t work.
I’ve used a print (itemRef) to see if A) the function was even activating and B) if itemRef itself was nil. The function worked perfectly and itemRef was the full copy I was hoping for–before it was returned. (And itemRef is 2-layer dictionary)
Also, the itemDatabase is wrapped in a function inside a module script. Since it handles player GUI, only the client ever uses it, so there’s no issue with “Server can’t invokeServer” type of stuff.
Code for modulescript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getDb = ReplicatedStorage.RemoteEvents:WaitForChild("getDatabase")
local updateGUI = {}
function updateGUI.fillCharSheet(userId, playerData)
local itemDatabase = getDb:InvokeServer()
print (itemDatabase)
--code continues, but is irrelevant
Code for serverscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local getDb = ReplicatedStorage.RemoteEvents:WaitForChild("getDatabase")
local function getDatabase()
return itemRef
end
getDb.OnServerInvoke= function(plyr)
getDatabase()
end
I believe that’s all the information needed. Here’s some background stuff, however, in case I can answer any possible questions.
itemRefs is a copy of the itemDatabase which is formatted like so:
Example:
[0004] = {
Name = 'Cool Item',
Type = 'gear',
Price = {5, 'gold'},
Weight = 4
},
[0005] = etc.
So on and so forth. itemRefs is a perfect copy so I don’t believe the code for that is at fault. ‘playerData’ doesn’t pertain to this issue, but it’s simply a copy of the data that the server has. This data is used to fill out most of the GUI. (And, credit where credit is due, the method I’m using for my itemDatabase is based on this helpful post)