Humanoid:AddAccessory() placing the accessory inside of the character model but it just falls to the floor and doesn't attach to the player's head

Basically I’m trying to make a GUI Button that gives the player an accessory
My code is:

button.MouseButton1Click:Connect(function()
Character.Humanoid:AddAccessory(accessory)
end)

  • It does spawn the accessory, but puts it in the workspace origin location and not in the player’s head.
1 Like

Could it be possible that the accessory’s Handle is anchored?

1 Like
button.MouseButton1Click:Connect(function()
Character.Humanoid:AddAccessory(HairClone) -- Adding the accessory
HairClone.Handle:WaitForChild("AccessoryWeld").Part1 = Character.Head -- Setting a weld's Part1 to the characters head.
end) 
1 Like

I checked, and it isn’t. Here’s my explorer inside of the GUI Frame.

image

I’ll try the code, thank you! (30 message characters)

Try the following?

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.Humanoid:AddAccessory(accessory)
end)
end)

Also, you have a MouseButton1Click, which is used for UI. You are only running this code on the client. Use a Remote Event to fire the server and place it properly. Else, the hat will only appear for the player.

is better you use a server event.

u need an EVENT in Replicated Storage
change de event name in the script, bc i called it “Equip”
and the hat is in the Replicated storage

NOTE: to the script works, The button NAME have to be the same of your HAT NAME

script in SSS

local replicatedStorage = game:GetService("ReplicatedStorage")
local equip = replicatedStorage:WaitForChild("Equip")
local hat = replicatedStorage.Halo1

equip.OnServerEvent:Connect(function(player, item)
	
	local character = player.Character
	local humanoid = character.Humanoid
	local clone = hat:Clone()
	humanoid:AddAccessory(clone)
		
end)

–script inside the button (localScript)

local replicatedStorage = game:GetService("ReplicatedStorage")
local gearEvent = replicatedStorage:WaitForChild("Equip")
local buy = script.Parent


buy.MouseButton1Click:Connect(function()
	  
	local item = buy.Name
	gearEvent:FireServer(item)
	
 end)
1 Like