Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

[Solved] having trouble with players buying an item?

Asked by 3 months ago
Edited 2 months ago

so here is the code

local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
    local MarketplaceService = game:GetService("MarketplaceService")
    local productID = 994379939
    MarketplaceService:PromptProductPurchase(player,productID)

    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
        if isPurchased == true then -- if player purchased the product
            player.leaderstats.lives.Value = player.leaderstats.lives.Value + 10
            print("suggsessful purchase")
        else
            print("Player did not purchase product")
        end
    end)
end)

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

local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
    local MarketplaceService = game:GetService("MarketplaceService")
    local productID = 994379939
    MarketplaceService:PromptProductPurchase(player,productID)

    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
        if isPurchased == true then -- if player purchased the product
            script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value + 10
        end
    end)
end)

1 answer

Log in to vote
1
Answered by 3 months ago
local player = script.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function()
    local MarketplaceService = game:GetService("MarketplaceService")
    local productID = 994379939
    MarketplaceService:PromptProductPurchase(player,productID)

    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
        if isPurchased == true then -- if player purchased the product
            script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value = script.Parent.Parent.Parent.Parent.Parent.leaderstats.lives.Value + 10
        end
    end)
end)
Ad

Answer this question