Good Day,
I am trying to set up a localscript to return data from ProfileService, I can get the data returned from money, but any of the other data such as backpackSize returns “nill”
ProfileService script snippiet
local ProfileStore = ProfileService.GetProfileStore(
"Player",
{
money = 0;
backpackName = "backpackLevel1";
backpackSize = 10;
backpackUsed = 0;
level = 0;
rebirths = 0;
}
)
Localscript calling Server script
Calling a server remotefuntion to return money and backpacksize
wait(5) -- Wait for Data to load
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataRequest = ReplicatedStorage:WaitForChild("DataRequest")
local dataReturned = DataRequest:InvokeServer("money")
print("Returned1 ", dataReturned)
wait(5) -- Wait for Data to load
local ReplicatedStorage2 = game:GetService("ReplicatedStorage")
local DataRequest2 = ReplicatedStorage2:WaitForChild("DataRequest")
local dataReturned2 = DataRequest2:InvokeServer("backpackSize")
print("Returned2 ", dataReturned2)
Server script
To handle returning the data
local DataManager = require(game.ReplicatedStorage:WaitForChild("ProfileService"):WaitForChild("DataManager-Module"))
-- Client to Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataRequest = Instance.new("RemoteFunction")
DataRequest.Parent = ReplicatedStorage
DataRequest.Name = "DataRequest"
local function onDataRequest(player, data)
if player then
local getData = DataManager:Get(player)
if getData then
if data == "money" then
print("money")
local returnMoney = getData.money
return returnMoney -- <<< THIS RETURNS CORRECTLY
elseif data == "backpackSize" then
print("backpackSize")
local returnBackpack = getData.backpackSize
return returnBackpack -- <<< THIS RETURNS NILL AND SHOULD BE 10
else
return 0
end
end
end
end
DataRequest.OnServerInvoke = onDataRequest