Ad
Log in to vote
1

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

Asked by 6 months ago

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

Log in to vote
0
Answered by
moo1210 16
6 months ago
Edited 6 months ago

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

Ad
Log in to vote
0
Answered by
Denny9876 1110 Moderation Voter
6 months ago
Edited 6 months ago

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.

0
This is under a text button. fuffieboy 5 — 6mo
Log in to vote
0
Answered by 6 months ago

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)

Answer this question