xynxae
(xynxae)
September 20, 2023, 1:41am
#1
Hi, developers!
I’m trying to make a 2x chance, but every time the player purchases the item, it seems to not be accurate when dividing. When I purchase the product 2 times, I should be at 250 chance, but… it apparently runs two extra times.
Studio Recording
As seen in my code I’m about to post, I’ve included:
return Enum.ProductPurchaseDecision.IsSuccessful
to try and stop the issue, but it doesn’t!!
here’s the full code btw!!!:
local button = script.Parent
local asset = 1647885321
button.MouseButton1Click:Connect(function()
local market = game:GetService('MarketplaceService')
market:PromptProductPurchase(game.Players.LocalPlayer, asset)
market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
if bought == true then
game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
print('plr bought asset')
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
end)
Any help is hugely appreciated, as I need the game released pretty soon!
niroqeo
(niro)
September 20, 2023, 1:45am
#2
xynxae:
local button = script.Parent
local asset = 1647885321
button.MouseButton1Click:Connect(function()
local market = game:GetService('MarketplaceService')
market:PromptProductPurchase(game.Players.LocalPlayer, asset)
market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
if bought == true then
game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
print('plr bought asset')
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
end)
It may be because a new PromptProductPurchaseFinished event is connected everytime the button is clicked. Try moving it outside of the button event?
local button = script.Parent
local asset = 1647885321
button.MouseButton1Click:Connect(function()
local market = game:GetService('MarketplaceService')
market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)
market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
if bought == true then
game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
print('plr bought asset')
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
1 Like
xynxae
(xynxae)
September 20, 2023, 1:51am
#3
Got an error right off the bat. I have no idea how PromptProductPurchaseFinished works, I even read the documentation, so my little hamster wheel of a brain cant figure out a solution.
niroqeo
(niro)
September 20, 2023, 1:53am
#4
thats my bad, marketserviceplace wasn’t defined
local button = script.Parent
local asset = 1647885321
local market = game:GetService('MarketplaceService')
button.MouseButton1Click:Connect(function()
market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)
market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
if bought == true then
game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
print('plr bought asset')
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
2 Likes
Haystees
(Haystees)
September 20, 2023, 1:53am
#5
Just make sure to define market outside of the button click.
local market = game:GetService('MarketplaceService')
button.MouseButton1Click:Connect(function()
market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)
market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
if bought == true then
game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
print('plr bought asset')
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
edit: nvm they got it first
xynxae
(xynxae)
September 20, 2023, 1:57am
#6
Worked like a charm. Thanks for the help!
1 Like