Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved] having trouble with players buying an item?

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.