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:
Client:
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
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.
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.
//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()