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