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

I need to find a t-shirt in the local players inv?

Asked by 3 years ago

so I need to detect if player has a t-shirt in there inventory, any help? I need like: if player has (the t shirt) then (I'll add code here) else (I'll add more code here)

1
Pair 'FindFirstChild' with a conditional statement. Ziffixture 6913 — 3y

1 answer

Log in to vote
0
Answered by
3F1VE 257 Moderation Voter
3 years ago

Use this for the client

local mps= game:GetService("MarketplaceService")
local id = 0123456789 -- t shirt id here
local lplr = game.LocalPlayer 
local check = mps:PlayerOwnsAsset(lplr,id)
if check == true then
print(lplr.Name.." owns asset : "..mps:GetProductInfoAsync(id))-- change this to what you want if they own it
else
print(lplr.Name.." does not own asset : "..mps:GetProductInfoAsync(id).." prompting purchase."
mps:PromptPurchase(lplr,id)
end

And this for the server

local mps= game:GetService("MarketplaceService")
local id = 0123456789 -- t shirt id here
game.Players.PlayerAdded:Connect(function(plr) -- fires when new player joins
local check = mps:PlayerOwnsAsset(plr,id)
if check == true then
print(plr.Name.." owns asset : "..mps:GetProductInfoAsync(id))-- change this to what you want if they own it
else
print(plr.Name.." does not own asset : "..mps:GetProductInfoAsync(id).." prompting purchase."
mps:PromptPurchase(plr,id)
end
Ad

Answer this question