Remote function always returning nil

Ah, I know that, I usually do that, just not this time :skull:.

1 Like

I assume you’ve added the return err at the end?

image

Nothing is outputted either way as shown here:

Like I said before, returning within a pcall will make the 2nd tuple your value (err), so you’ll have to return err where you return succ.

Additionally, use prints to identify which part of the if statement its returning (Error or Success), this will help us with more information regarding the current issue!

1 Like

Alright, there are print statements all over the script none of which print.

There seems to be some overcomplication in the provided answers to this post already. To explicitly respond to your initial post: your RemoteFunction handling appears fine. In a studio testing session or live game, there should be no issues. Testing with the output/console may lead to odd behavior because networking is involved but there may be no client/server to handle receiving/delivery.

This implies an issue with field:getInfo(), as others have mentioned. For the sake of testing your client code, I would recommend commenting out the entire function’s contents and returning just a simple value. Make sure you receive this value on the client as expected.

Then, move on to looking for issues in the function itself. Admittedly, it is odd that nil is being returned – at minimum, I would expect an empty table if every HTTP call silently failed, so look into that first. Otherwise, note that every HTTP call has a chance of failure and should be handled with a pcall.

1 Like

I commented it all out, and it still prints nil.
image

Can you share the Home script?

function field:GetInfoAsync()
	self["Services"] =  require(script.Parent.Parent.Services)

	self["Stats"] = FunctionStorage:FindFirstChild("Request"):InvokeServer("Statistics")

	task.wait()

	self["UI"] = script.Parent.Parent.Parent

	warn(self["Stats"])

	self["UI"].Panel.Pages.Home.Stats.Likes.TextLabel.Text = self["Stats"].Likes
	self["UI"].Panel.Pages.Home.Stats.Players.TextLabel.Text = self["Stats"].Visits
	self["UI"].Panel.Pages.Home.Stats.Uptime.TextLabel.Text = field:Convert(math.round(workspace.DistributedGameTime))

	task.delay(1,function()
		self:GetInfoAsync()
	end)
end

Edit: Didnt send the whole module as it has a lot of things not related to this topic.

Odd. Since you’re doing some metatable magic, for the sake of testing, I would try running this line either above/below self["Stats"] = FunctionStorage:FindFirstChild("Request"):...:

print(FunctionStorage:FindFirstChild("Request"):InvokeServer("Statistics"))

It’s unlikely, but possible, that self["Stats"] is being overwritten to nil or is referencing something different before it’s printed.

image
When I printed it, it did not print nil instead it printed " ".

1 Like

I’ll be afk for around 20-60 minutes, if you need more of the script here’s the file.

(FILE REMOVED)

Edit: Not AFK.

Back, did you figure out why this may be happening?

It seemed it just wasn’t being picked up in that script, I changed where it was being picked up from and it work’s fine now.

1 Like

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