Table made on server nil to client

Hi!

For my DS script (again lol), I’m creating a table on the server (PlotsOwned).

When I create it, I return it and then take it on the client.
But, the client is reading nil.
Server:
image
Client:
image

Code:

local SlotsToCreate = game.ReplicatedStorage.Datastore.RequestPlots:FireServer()
task.wait(5)
print(SlotsToCreate)
if SlotsToCreate == nil then
	NewSaveSlot("FYT2STARTERPLOT-"..Player.UserId.."-"..math.random(11111,99999999), "0", "Starter House: FYT2 Beginnings!", "0")
	print("Data was nil, gave StarterHouse")
	Stopped = true
end
if not Stopped then
for i, v in ipairs(SlotsToCreate) do
	local clone = script.Parent.SaveSelect.Template:Clone()
	clone.Parent = script.Parent.SaveSelect.List
	clone.Main.ID = v[2]
	clone.Main.PlotName = v[3]
	clone.Visible = true
	end
end
--//server
	local Data = {}
	Data = UserDS:GetAsync("Data") or {}
	local OwnedPlots = {}
	for i, v in ipairs(Data) do
		print(v)
		print("Temp_TableDataAbove!")
		if v[1] == Player.UserId then
			print("Found a match!")
			table.insert(OwnedPlots, v)
			else warn(v)
		end
	end
	warn(OwnedPlots)
	return OwnedPlots

Thanks!

I am not sure if remote event can return data like that maybe you should try fire remote back to client with data?

You can’t return values through a remoteEvent, you have to use a remoteFunction. The functions change slightly to InvokeServer() instead of FireServer, and on the server end, instead of running a function when an event is triggered, you have to do something like this:

remoteFunction.OnServerInvoke = getData --Just the function name, no parenthesis.
3 Likes

You either need to make use of a RemoteFunction as previously suggested or fire the client through a RemoteEvent instance and transmit the data stored/held within the variable “OwnedPlots” back to the client which initially fired the server.

I will try and fix after school sadly, give me a few hours. I overslept.

Remotefunctions are totally what you’re missing. Events are more for informing clients, or the server, about something.

Edit: Spelling

2 Likes

I now have this. It doesn’t work.

//client
SlotsToCreate = game.ReplicatedStorage.Datastore.RequestPlots:InvokeServer(player)
//server
function GetPlots(Player)
		print("On server!")
		print(Player.Name)
		local Data = {}
		Data = UserDS:GetAsync("Data") or {}
		local OwnedPlots = {}
		for i, v in ipairs(Data) do
			print(v)
			print("Temp_TableDataAbove!")
			if v[1] == Player.UserId then
				print("Found a match!")
				table.insert(OwnedPlots, v)
			else warn(v)
			end
		end
		warn(OwnedPlots)
		return OwnedPlots
end

game.ReplicatedStorage.Datastore.RequestPlots.OnServerInvoke = GetPlots()

It doesn’t do anything.

Remove the () after GetPlots()