Why is my datastore showing that money has been added, but doesn't really add?
Here is an image of what i'm talking about.
https://imgur.com/a/RtZxb7h
Here is the datastore script i'm using.
local DSService = game:GetService("DataStoreService"):GetDataStore("Leaderstats") game:GetService("Players").PlayerAdded:Connect(function(plr) local uniquekey = ("id-"..plr.UserId) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr local savevalue = Instance.new("IntValue") savevalue.Name = "Money" savevalue.Value = 500 savevalue.Parent = leaderstats local savevalue2 = Instance.new("IntValue") savevalue2.Name = "Gems" savevalue2.Value = 0 savevalue2.Parent = leaderstats local GetSaved = DSService:GetAsync(uniquekey) if GetSaved then savevalue.Value = GetSaved[1] savevalue2.Value = GetSaved[2] else local NumbersForSaving = {savevalue.Value, savevalue2.Value} DSService:SetAsync(uniquekey, NumbersForSaving) end end) game:GetService("Players").PlayerRemoving:Connect(function(plr) local uniquekey = ("id-"..plr.UserId) local Savetable = {plr.leaderstats.Money.Value, plr.leaderstats.Gems.Value} DSService:SetAsync(uniquekey, Savetable) end)
Since you are changing the stat on the Client, due to FilteringEnabled, it will not replicate to the Server. As a result, you will need to use a Remote Event to give the players their correct stat values.
local remote = Instance.new("RemoteEvent") remote.Name = "SaveValueEvent" remote.Parent = game:GetService("ReplicatedStorage") remote.OnServerEvent:Connect(function(plr, stat, val) if stat == "Money" then plr:WaitForChild("leaderstats"):WaitForChild("Money").Value = val elseif stat == "Gem" then plr:WaitForChild("leaderstats"):WaitForChild("Gems").Value = val end end)
local remote = game:GetService("ReplicatedStorage"):WaitForChild("SaveValueEvent") local plr = game:GetService("Players").LocalPlayer local money = plr:WaitForChild("leaderstats"):WaitForChild("Money") local gem = plr:WaitForChild("leaderstats"):WaitForChild("Gems") money.Changed:Connect(function() remote:FireServer("Money", money.Value) end) gem.Changed:Connect(function() remote:FireServer("Gem", gem.Value) end)
The above LocalScript simply sends the Server information when the values change on the Client (although this really should be done completely on the Server through the RemoteEvent)
Once the information is sent, the Server can then alter the leaderstat values, where they will be saved by your DataStore when the player leaves.