Scripting Money System Help

I need my script to not double the transaction every-time the event fires to give the player money.

Everytime the player buys a developer product or earns cash, it doubles after the second time they use the remote and it goes off from there.

I have looked at the server script and it seems even adding debounce wont work, and checking to see if the client sends double the amount, but I only included the amount in the server yet it still doubles the amount everytime.

I’ve tried every solution and I’m stuck at why the script is attempting to store the value after it has been given to the player. So in my mind it’s doing it right the first time. but after it’s done the first time, it stored the amount for the next purchase, so it adds it to there.

When watching the Gif, look at the output and look how it doubles the end.

bac5c063203af4ea7add9ecc82e385b0

You should use a debounce in you’re scripting checking if it isn’t already active.

I’ve attempted to do so, and it does the same thing.

Is that all your scripts ? or is there any other script susceptible of causing this issue.

https://gyazo.com/667864d223e15287d2015f134891f3eb

That’s the local script attached to the event

Are there currently any errors you could provide? It would be helpful if you could list errors, and screen shot them, also, before posting, making sure to debug is always a good path. Adding print() statements around your code will show what works, and if one of them does not print when it needs to, you then know where the code is messing up!

I’ll check it out now, I’m gonna make a dummy script and see if it does the same thing to see it’s the server or not.

1 Like

I still made a dummy script and it does the same thing, so I believe it might be the client?

What is your script exactly performing that you do not want it to?

I don’t want it to double the income they receive everytime they buy a developer product

It should only be like this.
Player press button: Player buys developer product: Player receives exact amount:done>
What my script does:
Player presses button: Player Buys developer product: Player receives twice as much as before.

So maybe when you fire the server wait for the receipt to print and then give them the goods? If you need an example let me know c:

How would I make it so the server returns the receipt true?

So you need me to provide an example?

Once the server is fired, fire the server with gamepassname, and gamepassiD

Do this;

local MPS = game:GetService("MarketplaceService")
MPS:PromptProductPurchase(player,id) --Prompt it server side, when they click only fire
MPS.ProcessReceipt = function(Recipt)
if Enum.ProductPurchaseDecision.PurchaseGranted and Recipt.PlayerId == player.userId then
  --give them the goods

Hope I helped :smiley:

1 Like

The first thing you need to do is remove that debounce. Having a global debounce like that will cause players to not be able to purchase if two players try to purchase something at the same time. The second thing is you can’t add Enum.ProductPurcahseDecision.NotProcessedYet in a if then statement. You have to return that at the end of the function. That’s why it’s doubling. I used to have this issue when I first started programming.

1 Like
if Enum.ProductPurchaseDecision.PurchaseGranted then

This doesn’t work!! You have to return this at the end of your ProcessReceipt function. You can’t check an Enum as Enums never change! This is what happens when you print the Enum. There’s no true false.

image

1 Like

Alright, thanks for letting me know I guess. If you noticed, it also Processes the receipt, and checks if the UserId is the same in the receipt, I am pretty sure if we remove the Enum the code would still work how it should. But I didn’t know that it doesn’t return true or false, thanks.

1 Like