Mannequin Purchase Clothing Button System

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I am attempting to make a system in which when a player clicks a button in the workspace next to a mannequin, a function will be called and they will be prompted to purchase the item that the mannequin is seen wearing in the workspace. There are two parameters of the function, the player who clicked the button, and the asset id of the item. The asset id of what I’d like the player to buy is in an IntValue inside of each mannequin model, with the value of the IntValue being set to the asset id of the shirt. There is more than you can understand by reading the code below.

  2. What is the issue? Basically what’s going on is when I click the button, it does not prompt me to purchase the item and instead an error is outputted that says “Argument 2 is missing or nil”.

  3. What solutions have you tried so far? Well, I’ve tried to fix the issue myself in Studio for the past hour or so, but didn’t have any luck. I’ve tried using :WaitForChild() on the IntValue, getting it’s value with tostring() and some different things, too. When you read the code, the whole idea of what I’m making is a little bit inefficient. I’m a pretty good scripter, and am making this as a little project to sharpen my knowledge in certain areas of Roblox Lua.

I should also mention that there are three mannequins, and I tried it on a random one of the three and the errors were on line 18 and 26.

This is the code:

local marketplaceService = game:GetService("MarketplaceService")

local mannequins = script.Parent

local m1 = mannequins.M1
local m2 = mannequins.M2
local m3 = mannequins.M3

local m1ClickDetector = m1.BuyShirt.ClickDetector
local m2ClickDetector = m2.BuyShirt.ClickDetector
local m3ClickDetector = m3.BuyShirt.ClickDetector

local m1ClothingId = m1.AssetId.Value
local m2ClothingId = m2.AssetId.Value
local m3ClothingId = m3.AssetId.Value

local function purchaseClothingItem(player,clothingid)




The issue is here:

This is because you have added 'm1ClothingId ’ inside your function. Since the MouseClick event does not return a second parameter, it gets set to nil. Just remove this and it will work:

Thank you very much! I can already tell that it will work for the other two MouseClick() events, one m2ClothingId and m3ClothingId are put inside of where they need to go.