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)
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)
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)
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)
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.
I read it and I thought I got it? I tried it out an got an error
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)
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()