How can I get the image ID from a marketplace ID using scripts

I am making a clothing store and im trying to automate needing to insert the marketplace ID into the Shirt/PantsTemplate

for h,o in pairs(game.Workspace.Clothing:GetDescendants()) do
	if o:IsA("Shirt") then
		o.ShirtTemplate = (o.Name)
		--The name would be 113336287803135 which is the marketplace ID
	end
	if o:IsA("Pants") then
		o.PantsTemplate = (o.Name)
		--The name would be 18746609119 which is the marketplace ID
	end
	if o:IsA("ClickDetector") then
		local bouuy = o.Parent.Parent.Name
		o.MouseClick:Connect(function(WHO)
			game:GetService("MarketplaceService"):PromptPurchase(WHO, bouuy)
		end)
	end
end

while this DOES work, it doesn’t work the way I want it to work by turning the mrktplc ID into the image ID as if you would to normally paste it into studio

Is there even a way to do this by script? I haven’t had any luck trying to look this up… my scripting knowledge is of a newbie so im pretty stumped on what to do…

This should be quite simple.

You would want to create a new instance for the shirt using:

local ShirtInstance = game:GetService("InsertService"):LoadAsset(ID):FindFirstChildWhichIsA("Shirt") --ID should be replaced by o.Name
local ID = "rbxassetid://"..(string.gsub(ShirtInstance.ShirtTemplate , "%D", ""))
1 Like

Yes!! this has worked, thnkyuu!

local InsertService = game:GetService("InsertService")

for h,o in pairs(game.Workspace.Clothing:GetDescendants()) do
	if o:IsA("Shirt") then
		--The name would be 113336287803135 which is the marketplace ID
		local Nshirt = InsertService:LoadAsset(o.Name):FindFirstChildWhichIsA("Shirt")
		local ShirtTemp = "rbxassetid://"..(string.gsub(Nshirt.ShirtTemplate , "%D", ""))
		o.ShirtTemplate = (ShirtTemp)
	end
	if o:IsA("Pants") then
		--The name would be 72677356622179 which is the marketplace ID
		local NPants = InsertService:LoadAsset(o.Name):FindFirstChildWhichIsA("Pants")
		local PantsTemp = "rbxassetid://"..(string.gsub(NPants.PantsTemplate , "%D", ""))
		o.PantsTemplate = (PantsTemp)
	end
	if o:IsA("ClickDetector") then
		local bouuy = o.Parent.Parent.Name
		o.MouseClick:Connect(function(WHO)
			game:GetService("MarketplaceService"):PromptPurchase(WHO, bouuy)
		end)
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.