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

[Solved] having trouble with players buying an item?

Asked by 4 years ago
Edited 4 years ago

so here is the code

01local player = script.Parent.Parent.Parent.Parent.Parent
02script.Parent.MouseButton1Click:Connect(function()
03    local MarketplaceService = game:GetService("MarketplaceService")
04    local productID = 994379939
05    MarketplaceService:PromptProductPurchase(player,productID)
06 
07    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
08        if isPurchased == true then -- if player purchased the product
09            player.leaderstats.lives.Value = player.leaderstats.lives.Value + 10
10            print("suggsessful purchase")
11        else
12            print("Player did not purchase product")
13        end
14    end)
15end)

when i run it and buy it there is an error saying: Script:9: attempt to index number with 'leaderstats' it happens at line 9 for some reason its not the line itself because ive put it at the top and that part works fine

edit: it works fine i solved it first person to say any answer gets a free point or whatever

01local player = script.Parent.Parent.Parent.Parent.Parent
02script.Parent.MouseButton1Click:Connect(function()
03    local MarketplaceService = game:GetService("MarketplaceService")
04    local productID = 994379939
05    MarketplaceService:PromptProductPurchase(player,productID)
06 
07    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
08        if isPurchased == true then -- if player purchased the product
09            script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value + 10
10        end
11    end)
12end)

1 answer

Log in to vote
1
Answered by 4 years ago
01local player = script.Parent.Parent.Parent.Parent.Parent
02script.Parent.MouseButton1Click:Connect(function()
03    local MarketplaceService = game:GetService("MarketplaceService")
04    local productID = 994379939
05    MarketplaceService:PromptProductPurchase(player,productID)
06 
07    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
08        if isPurchased == true then -- if player purchased the product
09            script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value + 10
10        end
11    end)
12end)
Ad

Answer this question