I have a script where the try on button lets you try on the hat or whatever. but the clone just keeps getting put on top. i’m not sure why. here’s my script.
local function equip()
if selected_item then
local handle = selected_item:WaitForChild("Handle")
if handle then
local human = character:WaitForChild("Humanoid")
local equipped_item = selected_item:Clone()
human:AddAccessory(equipped_item)
end
end
end
why does clone keep going to workspace instead of character/ human
I think what you could try is to set the Parent of the item before adding it to the humanoid
local function equip()
if selected_item then
local handle = selected_item:WaitForChild("Handle")
if handle then
local human = character:WaitForChild("Humanoid")
local equipped_item = selected_item:Clone()
equipped_item.Parent = character
human:AddAccessory(equipped_item)
end
end
end
Put the accessory in Replicated Storage and just parent it to the character through the script who is in Workspace. Make sure the Accessory is not on any character.
don’t know if i can do that the way my script is set up… if there’s multiple hats. how will i let the script know which hat to pull out of replicated storage
You could try something like to make it compatible with a parameter for the hat location
local function equip(hat)
if hat then
local handle = hat:WaitForChild("Handle")
if handle then
local human = character:WaitForChild("Humanoid")
local equipped_item = hat:Clone()
equipped_item.Parent = workspace --Or character if workspace doesn't work
human:AddAccessory(equipped_item)
end
end
end
This is a rough way to do but should do the trick.
Also I don’t know why you’re using WaitForChild for the Handle and checking if it exists without a TImeOut, since it can either infinitely yield or set the variable to the Handle, the variable’s a bit useless, although that’s my take and is unrelated to this
local function open_frame(curr)
frame:TweenPosition(UDim2.new(), "Out", "Quint", .5, true)
menu_open = true
local current = mouse.Target
local ugc_item = current.Parent
if ugc_item then
local ugc_clone = ugc_item:Clone()
ugc_clone.Parent = vpf
selected = ugc_clone
local vp_camera = Instance.new("Camera")
vpf.CurrentCamera = vp_camera
vp_camera.Parent = frame
vp_camera.CFrame = ugc_clone.CFrame * CFrame.Angles(0, math.rad(180), 0) + (ugc_clone.CFrame.LookVector * 5)
funcs.name_text()
funcs.price_text()
end
end
local function equip(hat)
if hat then
local handle = hat:WaitForChild("Handle")
if handle then
local human = character:WaitForChild("Humanoid")
local equipped_item = hat:Clone()
equipped_item.Parent = workspace --Or character if workspace doesn't work
human:AddAccessory(equipped_item)
end
end
end