Datastore2 not being correctly shown in leaderboard but saves correctly?

So I started using Datastore2 with Tables to improve my saving in game and I am just testing this out.
Basicly all i want right now is to correctly show the Leaderboard with the correct saved stats.

I am using a clickdetector to add +10 Money via remoteevents which works fine when I print the output.

local part = game.Workspace:WaitForChild("GiveMoney")
local DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
local event = game.ReplicatedStorage:FindFirstChild("FIREMONEY")

part.ClickDetector.MouseClick:Connect(function(plr)
	print(plr)
	local Stats = DataStore2("Stats", plr):Get()
	Stats.Money = Stats.Money + 10
	DataStore2("Stats",plr):Set(Stats)
	print(Stats.Money)
end)

Everytime I click the value gets higher, but the Leaderboard still shows 0

Here is my leaderboard script

local DataStore2 = require(game.ServerScriptService:WaitForChild("DataStore2"))	--get the datastore module
local MainKey = "MainKey"	--This is the Main key
DataStore2.Combine(MainKey, "Stats", "Weapons", "Cars", "Houses")	--Combine diffrent Keys to the Main key

--Data Table
local function SetDataTable()
	local UserData = {
		Stats = {
			["Money"] = 0,
			["Chips"] = 0,
		},
		Weapons = {
			["M4"] = false,
			["Pistol"] = false,
		},
		Cars = {
			["Mustang"] = false,
			["Truck"] = false,
		},
		Houses = {
			["House1"] = false,
			["House2"] = false,
			}
	}
	return UserData
end


--Main
game.Players.PlayerAdded:Connect(function(plr)
	
	local UserData = DataStore2(MainKey,plr):Get(SetDataTable())
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local weaponFolder = Instance.new("Folder")
	weaponFolder.Name = "Weapons"
	
	local carFolder = Instance.new("Folder")
	carFolder.Name = "Cars"
	
	local houseFolder = Instance.new("Folder")
	houseFolder.Name = "Houses"
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	
	local chips = Instance.new("IntValue")
	chips.Name = "Chips"
	
	local m4 = Instance.new("BoolValue")
	m4.Name = "M4"
	
	local pistol = Instance.new("BoolValue")
	pistol.Name = "Pistol"
	
	local mustang = Instance.new("BoolValue")
	mustang.Name = "Mustang"
	
	local truck = Instance.new("BoolValue")
	truck.Name = "Truck"
	
	local house1 = Instance.new("BoolValue")
	house1.Name = "House1"
	
	local house2 = Instance.new("BoolValue")
	house2.Name = "House2"
	
	local statsData = DataStore2("Stats",plr)
	local wepData = DataStore2("Weapons",plr)
	local carData = DataStore2("Cars",plr)
	local houseData = DataStore2("Houses",plr)
	
	local function UpdateStats(UpdateValue)	--Updates values to current data
		money.Value = statsData:Get(UpdateValue).money
		chips.Value = statsData:Get(UpdateValue).chips
	end
	
	local function UpdateWep(UpdateValue)
		m4.Value = wepData:Get(UpdateValue).m4
		pistol.Value = wepData:Get(UpdateValue).pistol
	end
	
	local function updateCar(UpdateValue)
		mustang.Value = carData:Get(UpdateValue).mustang
		truck.Value = carData:Get(UpdateValue).truck
	end
	
	local function updateHouse(UpdateValue)
		house1.Value = houseData:Get(UpdateValue).house1
		house2.Value = houseData:Get(UpdateValue).house2
	end
	
	--Updates and calls the function
	UpdateStats(UserData.Stats)
	UpdateWep(UserData.Weapons)
	updateCar(UserData.Cars)
	updateHouse(UserData.Houses)
	
	--Calls the functions on Update
	statsData:OnUpdate(UpdateStats)
	wepData:OnUpdate(UpdateWep)
	carData:OnUpdate(updateCar)
	houseData:OnUpdate(updateHouse)
	
	leaderstats.Parent = plr
	weaponFolder.Parent = leaderstats
	carFolder.Parent = leaderstats
	houseFolder.Parent = leaderstats
	
	--Parent to leaderstats folder
	money.Parent = leaderstats
	chips.Parent = leaderstats
	--Parent to weapons folder
	m4.Parent = weaponFolder
	pistol.Parent = weaponFolder
	--Parent to cars folder
	mustang.Parent = carFolder
	truck.Parent = carFolder
	--Parent to houses folder
	house1.Parent = houseFolder
	house2.Parent = houseFolder
end)

I would be very happy if someone can find out the issue and maybe tell me on what to improve! :))
~J

Did you even read the post? He is already doing this.

4 Likes