How would I script a model that when you click it and you click buy and its will prompt a purchase thingy?
Its a local script
For now :
Code I used
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local MSS = game:GetService("MarketplaceService")
for i,v in pairs(workspace.Clothing:GetChildren()) do
if v:IsA("Model") then
local clickDetector = Instance.new("ClickDetector",v)
clickDetector.MaxActivationDistance = 16
local billBoardGUI = script.BillboardGui:Clone()
billBoardGUI.Parent = script.Parent
billBoardGUI.Adornee = v.HumanoidRootPart
local tried = false
billBoardGUI.TryButton.Activated:Connect(function()
if tried == false then
local shirt = chr:FindFirstChildWhichIsA("Shirt")
if shirt then
tried = true
local currentTemplate = chr:FindFirstChildWhichIsA("Shirt").ShirtTemplate
shirt.ShirtTemplate = v:FindFirstChildWhichIsA("Shirt").ShirtTemplate
repeat wait() until tried == false
shirt.ShirtTemplate = currentTemplate
end
else
tried = false
end
end)
billBoardGUI.BuyButton.Activated:Connect(function()
game:GetService("MarketplaceService"):PromptPurchase(plr, v:FindFirstChild("AssetId").Value)
end)
local turnBool = false
clickDetector.MouseClick:Connect(function()
if turnBool == false then
turnBool = true
billBoardGUI.Enabled = true
else
turnBool = false
billBoardGUI.Enabled = false
end
end)
end
end
for i,v in pairs(workspace.Pants:GetChildren()) do
if v:IsA("Model") then
local clickDetector = Instance.new("ClickDetector",v)
clickDetector.MaxActivationDistance = 16
local billBoardGUI = script.BillboardGui:Clone()
billBoardGUI.Parent = script.Parent
billBoardGUI.Adornee = v.HumanoidRootPart
local tried = false
billBoardGUI.TryButton.Activated:Connect(function()
if tried == false then
local shirt = chr:FindFirstChildWhichIsA("Pants")
if shirt then
tried = true
local currentTemplate = chr:FindFirstChildWhichIsA("Pants").PantsTemplate
shirt.PantsTemplate = v:FindFirstChildWhichIsA("Pants").PantsTemplate
repeat wait() until tried == false
shirt.PantsTemplate = currentTemplate
end
else
tried = false
end
end)
billBoardGUI.BuyButton.Activated:Connect(function()
local Success2, Result2 = pcall(function()
return game:GetService("MarketplaceService"):GetProductInfo(v:FindFirstChild("AssetId").Value, Enum.InfoType.Asset)
end)
if Success2 and Result2 then
MSS:PromptPurchase(game.Players.LocalPlayer,Result2.ProductId)
end
end)
local turnBool = false
clickDetector.MouseClick:Connect(function()
if turnBool == false then
turnBool = true
billBoardGUI.Enabled = true
else
turnBool = false
billBoardGUI.Enabled = false
end
end)
end
end