I'm trying to make a datastore, however, I'm trying to transfer the points value to a server side script with a remote function. The problem seems to be embedded in:

getPoints.OnServerInvoke = function(player) blah blah...

When I access the 'data' variable, it won't work. Any solutions? (I tried printing data's value outside the function, it worked, however after I tested it inside, it wouldn't work.) Here is my code (serverSided):

(Don't worry about not having a playerRemoving part, I have it but didn't add that in the post)

local DataStoreService = game:GetService("DataStoreService")

local DataStore = DataStoreService:GetDataStore("ClientCurrencyData")

function onPlayerAdded(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local Points = Instance.new("IntValue")
	Points.Name = "Points"
	Points.Parent = leaderstats
	
	local Rank = Instance.new("StringValue")
	Rank.Name = "Rank"
	Rank.Parent = leaderstats
	
	local data 
	local success, errorMessage = pcall(function()
		data = DataStore:GetAsync(plr.UserId.."-points")
	end)
	if success then
		Points.Value = data
	else
		print("There was an error whilst recieving the Client's Data Key")
		warn(errorMessage)
	end
	
	if plr:IsInGroup(5265499) then
		Rank.Value = plr:GetRoleInGroup(5265499)
	end
	
	local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Accessing the targetted service
	local getPoints = ReplicatedStorage:WaitForChild("getPoints") -- Remote Function
	
	getPoints.OnServerInvoke = function(player)
		return data
	end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)