You have improper capitalization in the localscript for :GetService in line 2, but that should just make the script not work so are you sure that you don’t have another copy of the localscript you forgot to remove?
okay i think there might have been a dupe of the script so ive fixed the spelling mistake and removed the other script. now however it prompts the purchase but does not add the cash. does the regular script for checking the remote event need to be anywhere specific?
Sorry if i confused you i’m a little rusty i haven’t been in studio in a solid 8 months, have the server handle everything. Just use the localscript to detect when the button is clicked.
im not sure how to do that using another script. I only know how to check if it has been purchased using the same script do u know how i can do that in a different script?
Move everything you have besides what prompts the purchase to the server script and make it where the localscript just fires the remote event when the button is clicked and sends over the player, coins, and the id for the gamepass/dev product and in the server script you just do everything you did in the localscript (sorry for not having any scripts, i’m on phone so it’s a little hard)
maybe this will help because i’m not good at explaining:
Servers can only see changes made by client through remotes.
But what you are doing now is handling purchase through client which should not be the case, I didn’t even know you can call processreceipt from a localscript. You should only handle purchase from the server.
Also clearly stated in the documentation.
When i try handling the purchase in a server script i get this error:
MarketplaceService:PromptProductPurchase() player should be of type Player
Promptproductpurchase can be done on the client but the handling of the purchases has to be made on the server.
Yeah thats the issue i said about earlier im not sure how to handle the purchase using a different script to where it is prompted from
move the ProcessReceipt function to a server script
I’m on mobile right now so I can’t help much but it shouldn’t be too complicated, earlier you made a script OnServerEvent which changes the leaderstat value, use that same principle but through ProcessReceipt on a server script.
Its telling me i can only FireServer in a local script and thats part of the receipt that would need to be in a serverscript
You dont need that part anymore, from the serverscript set the value of the leaderstats.
You only use fireserver if you are trying to send value from the client. But right now you are handling everything on the server so you can remove that portion and just set the leaderstats value.
You can do something like this
local Players = game:GetService("Players")
local MPS = game:GetService("MarketplaceService")
local Products = {
[3238402896] = 1000; --Key is your DevProduct ID and the value is how much coins
} -- Your DevProducts ID
function handlePurchase(Player, ProductId)
if Products[ProductId] then
local leaderstats = Player:FindFirstChild("leaderstats")
if leaderstats then
local Coins = leaderstats:FindFirstChild("Coins")
if Coins then
Coins.Value += Products[ProductId]
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
MPS.ProcessReceipt = function(receiptinfo)
local Player = Players:GetPlayerByUserId(receiptinfo.PlayerId)
if not Player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return handlePurchase(Player, receiptinfo.ProductId)
end
I’m on mobile so there might be error
Yeah theres no error in that piece of code
The only thing i would recommend is if he is going to use more products that have different abilities he uses a product id as a key in the dictionary and its value is a function to perform its ability in the handle purchase function.