so basically I have a data store leaderstats script and it works but i'm trying to have the player be able to purchase a certain amount of something. so basically I want the player to click a button to confirm and then their cash stays the same exept subtracted by a value in replicated storage. heres what I have tried
-- code for the button script.Parent.MouseButton1Click:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer() end)
--script in serverscriptstorage game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) plr.leaderstats.Cash.Value -= game.ReplicatedStorage.SubtractVal.Value end)
--leaderstats code local datastores = game:GetService("DataStoreService") local store = datastores:GetDataStore("CashSave")
game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr
local Cash= Instance.new("NumberValue")
Cash.Name = "Cash"
Cash.Value = store:GetAsync(plr.UserId) or 0
Cash.Parent = leaderstats
local market = game:GetService("MarketplaceService")
market.ProcessReceipt = function(info)
local userid = info.PlayerId
local productid = info.ProductId
local plr = game.Players:GetPlayerByUserId(userid)
local leaderstats = plr.leaderstats
local coins = leaderstats.Cash
if productid == 1332434809 then
coins.Value += 10
elseif productid == 1332435305 then
coins.Value += 50
elseif productid == 1332435302 then
coins.Value += 100
elseif productid == 1332435304 then
coins.Value += 250
elseif productid == 1332435303 then
coins.Value += 500
elseif productid == 1332435306 then
coins.Value += 1000
elseif productid == 1332435307 then
coins.Value += 5000
elseif productid == 1332435301 then
coins.Value += 10000
end
end
end)
game.Players.PlayerRemoving:Connect(function(Plr) store:SetAsync(Plr.UserId,Plr.leaderstats.Cash.Value) end)
Can anyone help?

2 comments
I think he's trying to say how to make a purchase system that will remove his cash
I could be wrong