UPDATE
I copied my game into a new place and it fixed my problem but it causes animation bugs. How can I clear a datastore
DATA MANAGER
local ProfileService = require(game.ReplicatedStorage.ProfileService)
local Players = game:GetService("Players")
local ProfileStore = ProfileService.GetProfileStore(
"Player",
{
cash = 0;
bank = 0;
}
)
local Profiles = {}
local function playeradded(player)
local profile = ProfileStore:LoadProfileAsync(
"Player_" .. player.UserId,
"ForceLoad"
)
if profile then
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick("An error occured.")
end)
if player:IsDescendantOf(Players) then
Profiles[player] = profile
else
profile:Release()
end
else
player:Kick("An error occured.")
end
end
local function playerremoving(player)
local profile = Profiles[player]
if profile then
profile:Release()
end
end
Players.PlayerAdded:Connect(playeradded)
Players.PlayerRemoving:connect(playerremoving)
local DataManager= {}
function DataManager:Get(player)
local profile = Profiles[player]
if profile then
return profile.Data
end
end
return DataManager
Adds Money
local DataManager = require(game.ReplicatedStorage.DataManager)
game.ReplicatedStorage.RemoteEvents.axcv.OnServerEvent:Connect(function(plr)
local data = DataManager:Get(plr)
if data then
print(data.cash)
data.cash += 50
end
end)