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

Giving a player an item from a textbutton wont work?

Asked by 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

I'm making a GUI where you click a button and if you own the shirt then it will give you an item, and if you don't own it, it will prompt a purchase.

local ASSET_ID = 123456 --Asset Id here

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerOwnsAsset = MarketplaceService.PlayerOwnsAsset

script.Parent.MouseButton1Click:Connect(function(player)
    local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, ASSET_ID)
    if doesPlayerOwnAsset then
        local clone = game.ReplicatedStorage.item:Clone()
        clone.Parent = player.Backpack
    else
        game:GetService("MarketplaceService"):PromptProductPurchase(player, ASSET_ID)
    end
end)
0
What part of your script is the issue? Does it nit give the item? Does it not prompt the purchase? IAmNotTheReal_MePipe 418 — 4y
0
It says "Attempt to index "Nil" with backpack" co_existance 141 — 4y

1 answer

Log in to vote
0
Answered by
P100D 590 Moderation Voter
4 years ago

MouseButton1Click does not return a value so your player variable will always be nil.

In your LocalScript, you can get the current player by using

game:GetService("Players").LocalPlayer

If you need more info, you can find the documentation for MouseButton1Click here

Ad

Answer this question