So, I’m currently working on an avatar editor for my game, and there’s a rig meant to represent the player. This specific rig is client-cloned, and I’m trying to make it so that when the player clicks a ‘try’ button, it equips a hat onto the rig :
local button = script.Parent
local rs = game:GetService("ReplicatedStorage")
local GlobalTable = require(rs:WaitForChild("GlobalTable"))
local PirateHat = "PirateHat"
button.MouseButton1Click:Connect(function()
local rig = game.Workspace:WaitForChild("AvatarEditorCharacter")
local humOfRig = rig:WaitForChild("Humanoid")
local folder = rs:WaitForChild("Hats")
local accPirateHat = folder:WaitForChild("PirateHat"):Clone()
local foundPirate = false
for _, item in ipairs(GlobalTable.SelectedItem) do
if item == PirateHat then
foundPirate = true
break
end
end
if foundPirate then
humOfRig:AddAccessory(accPirateHat)
else
warn("Nothing found in the table")
end
end)
However, it doesn’t seem to actually do anything. I can see in the explorer that the hat has been parented and moved towards the rig, but I don’t see any changes happening to the rig itself, i dont see the hat being equipped, and i don’t know why. I’ve checked and confirmed that all attachments are in place, as suggested in this post but it’s still not working.
If anyone knows how to equip properly a client made hat towards a client made rig and know a solution to my script, i would be very grateful.
It looks like your script is attempting to clone a hat from ReplicatedStorage, but it might be missing some steps to properly equip the hat to the player’s rig. In Roblox, equipping accessories involves working with the character’s Humanoid and attaching the accessory to the correct location.
Here’s an updated version of your script with additional steps for properly equipping the hat:
local button = script.Parent
local rs = game:GetService("ReplicatedStorage")
local GlobalTable = require(rs:WaitForChild("GlobalTable"))
local PirateHat = "PirateHat"
button.MouseButton1Click:Connect(function()
local rig = game.Workspace:WaitForChild("AvatarEditorCharacter")
local humOfRig = rig:WaitForChild("Humanoid")
local folder = rs:WaitForChild("Hats")
local accPirateHat = folder:WaitForChild("PirateHat"):Clone()
-- Ensure the accessory has a Handle part
local handle = accPirateHat:FindFirstChild("Handle")
if not handle then
warn("The hat is missing a Handle part.")
return
end
-- Check if the accessory is already equipped
for _, accessory in pairs(humOfRig:GetAccessories()) do
if accessory.Name == accPirateHat.Name then
warn("The hat is already equipped.")
return
end
end
-- Attach the accessory to the character's head
local head = rig:WaitForChild("Head")
local hatAttachment = Instance.new("Attachment", head)
accPirateHat.Parent = hatAttachment
-- Attach the accessory to the humanoid
humOfRig:AddAccessory(accPirateHat)
end)
In this updated script:
I added a check to ensure that the accessory has a “Handle” part. This is crucial for attaching the accessory to the character.
I added a check to see if the hat is already equipped to prevent adding it multiple times.
I created a new Attachment for the hat, parented it to the character’s head, and then parented the hat to this attachment. This is a common practice for attaching accessories to specific body parts.
Make sure that the hat model in ReplicatedStorage has a “Handle” part that represents the main part of the accessory. If this doesn’t resolve the issue, you might want to check if there are any errors in the output or console that provide more information about what’s going wrong.
I don’t think you’ve read what I’ve been saying, i didnt ask for a chatGPT help inquiry on this cause the chatGPT version of my script does litellary the exact same thing and my issue is still here, my script is working just fine the problem is that i don’t see any hat on the rig despite seeing the opposite in the explorer as everything is client sided, and again there is no missing attachements i’ve already doubled checked that
And can i know why you decided to reply to my post with chatGPT? Seriously?
coming back on this, it appears that the position of the hat is not being updated despite the attachements being there, the hat does exist in the character though, so the issue is the accessory Handle position not being updated for some reason, this post has the same issue as me but it’s been 3 years already, i will mark this as a solution because i believe its a engine bug