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)
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.
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