Remote Function Not Returning Value

  1. 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.

  2. What is the issue? Include screenshots / videos if possible!
    The remote function is returning ‘nil.’

  3. 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)

All of your code is fine, other than a small oversight. In order for the RemoteFunction to return anything, you need to call return inside its invoke function.

getDb.OnServerInvoke= function(plyr)
	return getDatabase()
end

That should be all you need to do :slightly_smiling_face:

1 Like

…that worked.
Thank you so much!! And I am currently very frustrated with myself. But thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.