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

Why isn't my gear cloning into my backpack after gamepass purchase?

I'm trying to make it so right after I buy the pass, the gear is cloned into my backpack. What am I doing wrong?

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptPurchase(player, 237980461)
	if game.MarketplaceService:PlayerOwnsAsset(player, 237980461) then
	game.ServerStorage.SegwayHoverboard:Clone().Parent = player.Backpack
	player.Backpack.SegwayHoverboard.CanBeDropped = false
	game.SoundService.Ding:Play()
	end
end)

3 answers

Well I never do it that way, I always do it like this

local player = game.Players.LocalPlayer
local item = game.ServerStorage.SegwayHoverboard:Clone()
local market = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function()
    market:PromptPurchase(player, 237980461)
    if market:PlayerOwnsAsset(player, 237980461) then
    item.Parent = player.Backpack
    player.Backpack.SegwayHoverboard.CanBeDropped = false
    game.SoundService.Ding:Play()
    end
end)

Your welcome

Assuming you are using a local script, your script won’t work because ServerStorage can only be accessed by server scripts, not local scripts.

You can easily fix this by putting the item into ReplicatedStorage, where both server and local scripts can access them. Then you just change all those ServerStorage lines in your code into ReplicatedStorage.

Oh, and I don’t know if this is also a problem or not, but on line 5, I don’t think you can directly get the service using game, as it doesn’t show on your explorer tab. Try using game:GetService() again, or just set up a variable like what moo did.

1 comment

0

This is under a text button.

I fixed it.

local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local item = game.ServerStorage.SegwayHoverboard:Clone()
local market = game:GetService("MarketplaceService")

script.Parent.MouseButton1Click:connect(function()
    market:PromptPurchase(player, 237980461)
MarketplaceService.PromptPurchaseFinished:connect(function(player, assetId, isPurchased)
	if isPurchased then
		game.SoundService.Ding:Play()
    item.Parent = player.Backpack
    player.Backpack.SegwayHoverboard.CanBeDropped = false
	    end
end)
end)

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