Help With returning array through remote function

I’m learning about remote functions to create an inventory system that gets a list of pets owned by the player and returns it into a local script for the inventory GUI to use.

The list prints correctly but when the list is returned through the remote function it’s nil

Server side: (Prints the array correctly)

local function getdata(plr)
	local array = {}
	local petlist = game.ServerStorage.PlayerData:FindFirstChild(plr.UserId):WaitForChild("Pets"):GetChildren()
	for i, v in pairs(petlist) do
		table.insert(array,v)
	end
	print(array)
	return array
end

datagrabber.OnServerInvoke = function(plr)
	return getdata(plr)
end

Client Side: (Prints array as {} )

local function getpetdata(player)
	local data = datagrabber:InvokeServer(player)
	print(data)
	return data
end
while true do
	getpetdata(LocalPlayer)
	wait(1)
end

Looks like you are putting server side instances which do not replicate to the client. Try doing v.Name instead into the array.

1 Like

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