Hey,
I made a house purchase system, and when I buy a house, the money is deducted as shown in the console output. However, it doesn’t update in the leaderstats.
I have a part with a prompt that gives me coins, and that update does show on the leader stats. But when money is deducted, it doesn’t update there.
Could someone help me break this down and better understand what the issue is?
All the following scripts are located here:
Datamanager Module Script:
local Players = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local modules = serverScriptService:WaitForChild("Modules")
local ProfileService = require(modules:WaitForChild("ProfileService"))
local template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))
local datakey = "_DataStore"
local profileStore = ProfileService.GetProfileStore(datakey, template).Mock
local dataManager = {}
dataManager.Profiles = {}
function dataManager.GetProfile(player)
if not player:IsDescendantOf(Players) then return end
local profile = dataManager.Profiles[player]
while profile == nil do
profile = dataManager.Profiles[player]
task.wait()
end
return profile
end
local function PlayerAdded(player: Player)
local profile = profileStore:LoadProfileAsync("Player_"..player.UserId)
if profile ~= nil then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
dataManager.Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then
dataManager.Profiles[player] = profile
leaderstats:Create(player, profile)
else
profile:Release()
end
else
player:Kick()
end
end
local function PlayerRemoving(player: Player)
local profile = dataManager.Profiles[player]
if profile ~= nil then
profile:Release()
end
end
for _, player in Players:GetPlayers() do
task.spawn (PlayerAdded, player)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
return dataManager
Leaderstats Module:
local module = {}
function module:Create(player: Player, profile)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local coin = Instance.new("IntValue")
coin.Name = "Coin"
coin.Value = profile.Data.Coin
coin.Parent = leaderstats
end
return module
Template Module:
local template = {
Coin = 0,
}
return template
Playerdata Script:
require(script.Parent:WaitForChild("Modules"):WaitForChild("DataManager"))