Problem With Leaderstats

Hi, I am having a problem with my cash leaderstat. The problem comes when I have a developer product that should set the cash to 1000. It works but only client sided as when i use something that costs cash it instantly goes back to the value it was before. For example if my cash was 50 and i set it to 1000 then spent 25 it would go to 25 instead of 975.

Here is the code that i have for my developer product:

local button = script.Parent 
local mpService = game:getService("MarketplaceService")
local players = game:GetService("Players")
local productID = 3238402896
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AddCoinsEvent = ReplicatedStorage:WaitForChild("AddCoinsEvent")
local Coins = 1000

button.MouseButton1Click:connect(function()
	mpService:PromptProductPurchase(plr, 3238402896)  
end)														
mpService.ProcessReceipt = function(recieptInfo)
	local playerPurchasing = players:GetPlayerByUserId(recieptInfo.PlayerId)
	if not playerPurchasing then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if recieptInfo.ProductId == productID then
		AddCoinsEvent:FireServer(Coins)
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

AddCoinsEvent.OnServerEvent:Connect(function(player, coinsToAdd)
	
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		local coins = leaderstats:FindFirstChild("Coins")
		if coins then
			coins.Value = coinsToAdd
		end
	end
end)

this is all in a localscript that is why.

you are setting the amount of coins inside of the localscript which will not work.

essentially you need to handle products on the server side

Yeah i thought that but i thought using a remote event would update it for the server?

is the bottom text in a separate script or is this all one localscript?

dont use remote events just use a bindable event or functions

Its all inside the same script

So don’t set the coins inside of that, you have to let the server do that.

so how can i do that because i tried having it in a regular script and it ended up with the same result or the product purchase not working at all

You prompt them inside a localscript then use a remote event to have the server add the coins. If you do this you have to make sure it’s secure though or else hackers can abuse it.

can i fire the remote event from within the same local script and then check for it in a regular script?

he doesnt need a remote event just use module scripts to add the coins and connect that to the product purchase handling

Fire it inside the localscript then have a script wait for the event to be fired then add the coins

yeah there are multiple ways of doing it

Okay i will give that a try then

i know but remote events are a waste in this case

It still works and is easy to understand

Okay i tried adding it to a regular script and i still have the same result. this is what ive put in my regular script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AddCoinsEvent = ReplicatedStorage:WaitForChild("AddCoinsEvent")


AddCoinsEvent.OnServerEvent:Connect(function(player, coinsToAdd)
	
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		local coins = leaderstats:FindFirstChild("Coins")
		if coins then
			coins.Value = coinsToAdd
		end
	end
end)

and this is what is now in the local script:

local button = script.Parent
local mpService = game:getService("MarketplaceService")
local players = game:GetService("Players")
local productID = 3238402896
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AddCoinsEvent = ReplicatedStorage:WaitForChild("AddCoinsEvent")
local Coins = 1000

button.MouseButton1Click:connect(function()
	mpService:PromptProductPurchase(plr, 3238402896)  
end)														
mpService.ProcessReceipt = function(recieptInfo)
	local playerPurchasing = players:GetPlayerByUserId(recieptInfo.PlayerId)
	if not playerPurchasing then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if recieptInfo.ProductId == productID then
		AddCoinsEvent:FireServer(Coins)
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

So it still looks like it gives it but in reality it doesn’t?

yeah thats still the case, updates client side but then returns to the original value after i purchase something