I’m making a try on/take off system.
here’s my mannequin code (only using pants)
local clickDetector = script.Parent.ClickDetector
local originalPantsFolder = game.Workspace:FindFirstChild("OriginalPants")
local triedOn = game.ReplicatedStorage.triedOn
local cooldown = 3
local lastClickTime = {}
local hasInteracted = {}
local function onClick(player, pants, clickDetector)
print("Mannequin clicked by:", player.Name)
local currentTime = tick()
if lastClickTime[player] and currentTime - lastClickTime[player] < cooldown then
print("Cooldown in effect. Please wait before clicking again.")
return
end
if hasInteracted[player] then
print("Mannequin has already been interacted with by this player.")
triedOn:FireClient(player)
return
end
local character = player.Character or player.CharacterAdded:Wait()
print("Character:", character)
-- Find the OriginalPants inside the character and move them back if found
local originalPants = character:FindFirstChild("OriginalPants")
if originalPants then
print("Found OriginalPants inside character, moving them back...")
originalPants.Parent = originalPantsFolder
print("Moved OriginalPants back to the folder")
end
-- Remove existing pants
for _, item in ipairs(character:GetChildren()) do
if item:IsA("Pants") then
if not item:GetAttribute("Temporary") then
item:Destroy()
print("Removed existing pants")
end
end
end
-- Equip new pants
local pantsClone = pants:Clone()
pantsClone.Parent = character
print("Equipped new pants")
-- Enable pants GUI (assuming it's a child of the mannequin)
local pantsGUI = clickDetector.Parent:FindFirstChild("PantsGui")
if pantsGUI then
pantsGUI.Enabled = true
pantsGUI.Parent = player.PlayerGui
print("Enabled pants GUI")
else
print("Pants GUI not found.")
end
lastClickTime[player] = currentTime
hasInteracted[player] = true
end
local function onMannequinClicked(player)
onClick(player, clickDetector.Parent.Pants, clickDetector)
end
clickDetector.MouseClick:Connect(onMannequinClicked)
now, the code sort of works. when i try to click on another mannequin, it says it can’t detect the originalPants, even though it’s in the character.
the gui’s no button script (which moves the originalPants back into the character):
-- Assuming this is attached to a button within a GUI
local originalPantsFolder = game.Workspace:WaitForChild("OriginalPants")
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local originalPants = originalPantsFolder:FindFirstChild("OriginalPants")
if originalPants then
-- Remove any temporary pants first
for _, item in pairs(character:GetChildren()) do
if item:IsA("Pants") and item:GetAttribute("Temporary") then
item:Destroy()
end
end
-- Remove the equipped pants
local equippedPants = character:FindFirstChild("Pants")
if equippedPants then
equippedPants:Destroy()
end
-- Clone the original pants
originalPants.Parent = character
-- Remove the original pants from the originalPantsFolder
-- Disable the GUI button after equipping the original pants
script.Parent.Parent.Parent.Enabled = false
else
print("Original pants not found for player:", player.Name)
end
end
end
end)
i’ve looked everywhere and found no solutions.