I'm making a shop and it works fine just when I leave and enter the game, I have the same amount of money before I bought the item and the item is not in my inventory?
Scripts:
Data Store
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("Purchases1SaveSystem")
local ds2 = datastore:GetDataStore("Purchases2SaveSystem")
local ds3 = datastore:GetDataStore("PurchasesSaveSystem")
local ds4 = datastore:GetDataStore("Purchases3SaveSystem")
game.Players.PlayerAdded:connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats1"
local purchases1 = Instance.new("IntValue", folder)
purchases1.Name = "Purchases1"
local purchases2 = Instance.new("IntValue", folder)
purchases2.Name = "Purchases2"
local purchases = Instance.new("IntValue", folder)
purchases.Name = "Purchases"
local purchases3 = Instance.new("IntValue", folder)
purchases3.Name = "Purchases3"
purchases1.Value = ds1:GetAsync(plr.UserId) or 0
ds1:SetAsync(plr.UserId, purchases1.Value)
purchases2.Value = ds2:GetAsync(plr.UserId) or 0
ds2:SetAsync(plr.UserId, purchases2.Value)
purchases3.Value = ds4:GetAsync(plr.UserId) or 0
ds4:SetAsync(plr.UserId, purchases3.Value)
purchases.Value = ds3:GetAsync(plr.UserId) or 0
ds3:SetAsync(plr.UserId, purchases.Value)
purchases1.Changed:connect(function()
ds1:SetAsync(plr.UserId, purchases1.Value)
end)
purchases3.Changed:connect(function()
ds4:SetAsync(plr.UserId, purchases3.Value)
end)
purchases2.Changed:connect(function()
ds2:SetAsync(plr.UserId, purchases2.Value)
end)
purchases.Changed:connect(function()
ds3:SetAsync(plr.UserId, purchases.Value)
end)
end)
Shop (Item)
local item = script.Parent
local rs = game.ReplicatedStorage
local Noob = script.Parent.Parent.Parent.Frame3.Equip.Noob
local value = 10
item.MouseButton1Click:connect(function()
if game.Players.LocalPlayer.leaderstats.Money.Value >= value then
game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - 0
item.Text = "Purchased"
Noob.Visible = true
value = 0
script.Parent.Parent.Parent.Frame3.Locked.Noob1.Visible = false
script.Parent.Parent.Parent.Available.Visible = true
wait(2)
script.Parent.Parent.Parent.Available.Visible = false
else
item.Text = "Purchase Failed"
wait(1)
item.Text = "Noob $10"
if game.Players.LocalPlayer.leaderstats1.Purchases3.Value == 4 then
value = 0
Noob.Visible = true
end
end
end)
Inventory Data Store Recognition
local purchases = game:WaitForChild("Players").LocalPlayer:WaitForChild("leaderstats1"):WaitForChild("Purchases3")
purchases.Changed:Connect(function()
if purchases.Value == 4 then
print("NoobT")
script.Parent.Visible = true
script.Parent.Parent.Parent.Locked.Noob1.Visible = false
else
print("Bye")
script.Parent.Visible = false
end
end)
I have been trying to fix this for weeks and am still learning LUA, I'd really appreciate it if you could help! Thanks!

5 comments
If you are testing this script in studio, you must first enable studio access to API services. Also, in order for the player removing function to activate as intended, you must go into the player menu and push leave game while testing it like you would in a real Roblox game.
If you just push the stop button while testing, that immediately ends all processes and the script won't receive the player removing signal, hence not saving your data like it should.
I apologize if these comments are irrelevant and don't work for you, this is just what happened to me and it was extreeeeemely frustrating. If you are already doing these things just tell me and I can delete these comments.
Thank you for these comments although it is not my data store that is the issue. I have a working data store with money and kills and that works fine, this data store is the exact same set up but with different tites. I am thinking about using badges instead of invisible leaderstats, so when you purchase an item you get a badge and then a script can detect if you own said badge, if you do own-
said badge, it will give you the item, if not say "You do not own this item"