How do i detect user input and change the clothing IDs on a mannequin?

I want to make a game that has a thing where you can click on a mannequin and give it clothing according to the id. I have my code set to change a specific mannequin, but I really want it to change whatever mannequin was clicked on.

I am fairly new to coding so apologies if this is a dumb question.

in my workspace I have this dummy with a script inside a click detector:

local clickfinder = script.Parent

clickfinder.MouseClick:Connect(function(Player)
	print(Player.Name.." clicked me!")
	if Player.PlayerGui.GiverGui.Enabled == false then
		Player.PlayerGui.GiverGui.Enabled = true
	end
end)

I only worked on the pants script currently!
In my gui I have this text box with this script:

local pantsgiver = game.Workspace.Mannequin
local SetPants = script.Parent

SetPants.FocusLost:Connect(function(enterpressed)
	if enterpressed then
		pantsgiver:FindFirstChild("Pants").PantsTemplate = SetPants.Text
	end
end)

here is footage of me testing my code.

3 Likes

Try this? Just an idea

local pantsgiver = game.Workspace.Mannequin
local SetPants = script.Parent
local Prefix = "rbxassetid://"
SetPants.FocusLost:Connect(function(enterpressed)
	if enterpressed then
		pantsgiver:FindFirstChild("Pants").PantsTemplate = Prefix..SetPants.Text
	end
end)
3 Likes

aaaaaaaaaaa this didnt work : (

3 Likes

Have you tried adding prints to see if this line of code runs. Like:

local pantsgiver = game.Workspace.Mannequin
local SetPants = script.Parent
local Prefix = "rbxassetid://"
SetPants.FocusLost:Connect(function(enterpressed)
	if enterpressed then
print("Setting dummy pants ID")
		pantsgiver:FindFirstChild("Pants").PantsTemplate = Prefix..SetPants.Text
	end
end)
1 Like

Oh yeah I just tested this, doesn’t print anything. Dunno why

Is this a local script in the gui to detect FocusLost?

1 Like

This is a server script not a local one. Is that the issue?

1 Like

Yes. TextBox focus needs to be on the client, or a local script. According to the FocusLost docs

2 Likes

Click Detector script:

local clickfinder = script.Parent

clickfinder.MouseClick:Connect(function(Player)
	print(Player.Name.." clicked me!")
	if Player.PlayerGui.GiverGui.Enabled == false then
		local Target = Player:FindFirstChild("Mannequin")
		if not Target then
			Target = Instance.new("ObjectValue")
			Target.Name = "Mannequin"
			Target.Parent = Player
		end
Target.Value = script.Parent.Parent
		Player.PlayerGui.GiverGui.Enabled = true
	end
end)

GUI script (make sure its a LocalScript)

local SetPants = script.Parent
local Prefix = "rbxassetid://"
SetPants.FocusLost:Connect(function(enterpressed)
	if enterpressed then
print("Setting dummy pants ID")
		game.Players.LocalPlayer.Mannequin.Value:FindFirstChild("Pants").PantsTemplate = Prefix..SetPants.Text
	end
end)
3 Likes


I got this error

1 Like

I edited the mannequin code. Try that.

The print worked this time and there was no error, but nothing happened. : (

edit: I noticed it sets the ID, but it just doesn’t show it. I saw a post on this once but I can’t find it.
image

Edit 2: I found the post, but it doesn’t work on local scripts.

poke (if roblox forums boost posts by replies)

I tried to make it send the code to a value inside the dummy then have a script that checks when the value updates. the script was supposed to load the id to the game and give it to the dummy but it didn’t work.

Not 100% sure since I haven’t messed with assets too much but I believe this must be set server side for it to load. Try sending it through a remote and set it through the server.

Let me know if it works!

I am super new to coding what do you mean by that? sorry : (

Read all about it here! Let me know if it makes sense after a read.

Now that I think about it this one sounds more beginner friendly. Here you go.

I was about to say i physically couldnt read the first one :sob:

1 Like

I read it and I thought I got it? I tried it out an got an error :sob:
image
these were the events I made (ignore the shirt one im doing that one after I figure out the pants one!!)

script in the dummy:

local clickfinder = script.Parent
local mannequin = script.Parent.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventPants = ReplicatedStorage:FindFirstChild("PantsMannequinChanged")


clickfinder.MouseClick:Connect(function(Player)
	print(Player.Name.." clicked me!")
	if Player.PlayerGui.GiverGui.Enabled == false then
		local Target = Player:FindFirstChild("Mannequin")
		if not Target then
			Target = Instance.new("ObjectValue")
			Target.Name = "Mannequin"
			Target.Parent = Player
		end
		Target.Value = mannequin
		Player.PlayerGui.GiverGui.Enabled = true
	end
end)



-- Get reference to remote event instance

local function changePants(id)
	mannequin.Pants.PantsTemplate = id
end

-- Connect function to event
remoteEventPants.OnServerEvent:Connect(changePants)

script in the textbox:

local SetPants = script.Parent
local Prefix = "rbxassetid://"
local Marketplace = game:GetService("MarketplaceService")
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventPants = ReplicatedStorage:FindFirstChild("PantsMannequinChanged")

SetPants.FocusLost:Connect(function(enterpressed)
	if enterpressed then
		print("Setting dummy pants ID")
		local IsClothingValid = pcall(Marketplace.GetProductInfo, Marketplace, SetPants.Text)
		if IsClothingValid then
			print("Valid Id. Checking if it is pants....")
			local ProductInfo = MarketPlaceService:GetProductInfo(tonumber(SetPants.Text))
			if ProductInfo.AssetTypeId == 12 then
				print("Success!")
				remoteEventPants:FireServer(Prefix..SetPants.Text)
			else 
				print("Please use a pants ID.")
			end
		else 
			print("Invalid ID.")
		end
	end
end)

the error:
image

image

I had this exact same problem in my game, for some reason scripts cant change pants and shirts of rigs and you have to use insert service.

heres the code I used I found it in my game

local model =  game:GetService("InsertService"):LoadAsset(id)
	local pants = model:WaitForChild("Pants")
	local clone = pants:Clone()
	clone.Parent = -- your model 
	model:Destroy()

has to be done serverside btw