Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cloning script clones object the amount of times player has bought dev product?

Asked by 6 years ago
Edited 6 years ago

The script below is supposed to spawn one object once the dev product has been purchased. When you buy the dev product the first time, it will spawn once as it should. But when you buy the dev product again it will spawn two at once instead of one.

local link = game:GetService("MarketplaceService")
deb = 0


script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local marketId = 377473848 --ID OF YOUR DEVELOPER PRODUCT  
if deb == 0 then
    deb = 1
    link:PromptProductPurchase(plr,marketId)
    link.ProcessReceipt = function(receiptInfo)
    if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId then
        local megalodon = game:GetService("ServerStorage").Megalodon:Clone()
        megalodon.Parent = game.Workspace
        megalodon:MakeJoints()
        megalodon:MoveTo(workspace.SharkPoint2.Position)
        wait(1)
    deb = 0
end
end
end
end)
0
Is that during a game if you bought twice or different servers? Decimaprism 65 — 6y
0
The first time you buy it, it will spawn once. Buying it more than once will cause it to spawn two at a time GlobeHousee 50 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

The simple answer is you don't have anything to prevent it from copying again.

The long answer is to prevent the issue try this "if" statement:

if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId and not game.Workspace.SharkPoint2:FindFirstChild("Megalodon")
    --Your code here
end

If you have any questions or issues please contact me. ;)

0
I actually just found out that the thing spawns in the amount of times you buy it. If i buy the megalodon 5 times, it will spawn 5 at a time. GlobeHousee 50 — 6y
0
Yeah, I figured. This should fix that issue anyways. lazycoolboy500 597 — 6y
0
If this actually helped, I recommend accepting this as the answer; accepting would allow people to know for sure this fixed the issue. lazycoolboy500 597 — 6y
Ad

Answer this question