ProfileService not returning data correctly

I’m currently creating local GUI to show stats etc. I’m running through some troubles displaying data. I’ve set up a remote to request the server. Im just wondering what techniques i could use to store data in the game/easily access them.

Heres the serverscript

local DataHandler = require(game.ReplicatedStorage.DataHandler)

local Request = game.ReplicatedStorage["Remote Events"].RequestStat

local RequestStat = {}

function RequestStat:Init()
	RequestStat.OnServerInvoke:Connect(function(Player,Stat)
		local Data = nil
		repeat 
			wait()
			Data = DataHandler:Get(Player)
		until Data ~= nil
		return Data[Stat]
	end)
end

return RequestStat

Bonus if you can tell me how to create global datastore with profileservice

(Sorry im new to profileservice and im creating a game that has it inside without much knowledge.)

I made this script to store data in game but it doesnt refresh stats correctly… So if anyone also has a solution to the following script it would be lovely :slight_smile:

local RunService = game:GetService("RunService")

local DataHandler = require(game.ReplicatedStorage.DataHandler)

local FoodInfo = require(game.ReplicatedStorage.Modules.FoodInfo)
local Stat = {}

local Template = DataHandler:Template()

function Stat:CreateStats(Player)
	local Folder = Instance.new("Folder")
	Folder.Name = "Stats"
	Folder.Parent = Player
	
	print(DataHandler:Template())	
	for i,v in pairs(Template) do
		print(i,v)
		if v=="true" or v=="false" then
			local Val = Instance.new("BoolValue")
			Val.Name = i
			Val.Parent = Folder
		else
			local Val = Instance.new("StringValue")
			Val.Name = i
			Val.Parent = Folder
		end
	end
end

function Stat:CreateLeaderstats(Player)
	local LS = Instance.new("Folder")
	LS.Name = "leaderstats"
	LS.Parent = Player
	
	local Moneys = Instance.new("StringValue")
	Moneys.Name = "Cash"
	Moneys.Parent = LS
	
	local Rebirths = Instance.new("StringValue")
	Rebirths.Name = "Rebirths"
	Rebirths.Parent = LS
	
	local Data = nil
	repeat
		wait()
		Data = DataHandler:Get(Player) 	
	until Data ~= nil
	
	coroutine.resume(coroutine.create(function()
		RunService.Heartbeat:Connect(function()
			Moneys.Value = "$"..Data.Cash
			Rebirths.Value = Data.Rebirths
			for i,v in ipairs(Player.Stats:GetChildren()) do
				v.Value = tostring(Data[v])
			end
		end)
	end))
end

function Stat:Init()
	game.Players.PlayerAdded:Connect(function(Player)
		self:CreateLeaderstats(Player)
		self:CreateStats(Player)
	end)
end
return Stat

Use ReplicaService topcst goofy

What do u mean lobre to do what