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

how do i make a game check if player owns asset?

Asked by 4 years ago

how do I make a script that checks if player owns an asset

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

Please read this:https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PlayerOwnsAsset

The above code shows whether the player owns an asset if they do then it will return true

-- The item we're checking for: https://www.roblox.com/catalog/30331986/Midnight-Shades
local ASSET_ID = 30331986
local ASSET_NAME = "Midnight Shades"

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

Players.PlayerAdded:Connect(function (player)
    local success, doesPlayerOwnAsset = pcall(PlayerOwnsAsset, MarketplaceService, player, ASSET_ID)
    if doesPlayerOwnAsset then
        print(player.Name .. " owns " .. ASSET_NAME)
    else
        print(player.Name .. " doesn't own " .. ASSET_NAME)
    end
end)
Ad

Answer this question