Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Hat doesn't Clone to Character?

Hello! I am trying to make a hat shop for my game. As you can see here, I'm trying to clone a hat to a player's character, but it's not working. When I go test it, it shows that the accessory is in the character model, however you can't see the accessory. Here is my code:

1	local player = game.Players.LocalPlayer
2	 
3	script.Parent.MouseButton1Click:Connect(function(click)
4	    if player.leaderstats.Coins.Value >= 100 then
5	        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 100
6	        game.ReplicatedStorage.Hats.RedSparkletimeFedora:Clone().Parent = player.Character
7	    end
8	end)

Below, you can see that the accessory is in my character, but doesn't appear to be on my character. I'm fairly new too scripting. I've read that sometimes when accessories are cloned, their AccessoryWelds disappear, but I'm not sure if that's the case here. Any help is much appreciated!

https://ibb.co/0JsCw31

https://ibb.co/S5GDYB5

1 answer

✓ Accepted answer

This is a fairly easy to solve problem. You can parent it to the model but it isn't going to just "attach" to it. You need to tell it how to attach. This can be done with AddAccessory()

Try looking here: https://developer.roblox.com/en-us/api-reference/function/Humanoid/AddAccessory

As this will properly parent AND PROPERLY ATTACHES < that caps bit is what you're missing.

Here is an example:

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
 
-- Create the Accessory.
local clockworksShades = Instance.new("Accessory")
clockworksShades.Name = "ClockworksShades"
 
local handle = Instance.new("Part")
handle.Name = "Handle"
handle.Size = Vector3.new(1,1.6,1)
handle.Parent = clockworksShades
 
local faceFrontAttachment = Instance.new("Attachment")
faceFrontAttachment.Name = "FaceFrontAttachment"
faceFrontAttachment.Position = Vector3.new(0,-0.24,-0.45)
faceFrontAttachment.Parent = handle
 
local mesh = Instance.new("SpecialMesh")
mesh.Name = "Mesh"
mesh.Scale = Vector3.new(1,1.3,1)
mesh.MeshId = "rbxassetid://1577360"
mesh.TextureId = "rbxassetid://1577349"
mesh.Parent = handle
 
-- Attach the Accessory to the humanoid.
humanoid:AddAccessory(clockworksShades)

This basic example takes an accessory and attaches it. In your case, you can just take your game.ReplicatedStorage.Hats.RedSparkletimeFedora:Clone()

and but that into the brackets.

1 comment

0

Thank you so much! This was exactly what I was looking for!

This discussion is preserved as it was. New answers, comments, and votes are closed.