Help with avatar accessory in game not attaching to players head

So recently i modeled a mask for my game and made a wear button gui to go with it, but i have encountered an issue where it does parent the accessory to my character but it does not attach to it… It just falls and when i jump it pushes me away. No idea why this is happening since i am new to creating my own in game accessories.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
	local mask = game.ReplicatedStorage["Mask"]
	if char:FindFirstChild("Mask") then
		char:FindFirstChild("Mask"):Destroy()
	else
		local mask = game.ReplicatedStorage["Mask"]
		mask:Clone().Parent = char
		
	end
end)
1 Like

Does the accessory have a “Handle” part inside of it?

2 Likes

Yes, yes it does. I already checked if it was that but it does have.

1 Like

Does the accessory have an attachment in the Handle with the same name as one of the attachments in the character?

For example, my accessory has an attachment with the name “HatAttachment” which means the game will make a weld from the accessory attachment to the attachment with the same name in the character
image
image

2 Likes

Yes they both have the attachment same name same everything.

1 Like

Do you mind sending an image of the Accessory and all of its children?

2 Likes

Screenshot 2024-05-26 at 3.41.43 p.m.

1 Like

Try this

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
	local mask = game.ReplicatedStorage["Mask"]
	if char:FindFirstChild("Mask") then
		char:FindFirstChild("Mask"):Destroy()
	else
		local mask = game.ReplicatedStorage["Mask"]
		char:FindFirstChild("Humanoid"):AddAcessory(mask:Clone())
	end
end)

I just added the AddAcessory thingy

1 Like

I think I found your problem: the script that gives the accessory is local so it doesn’t replicate to the server. Maybe put a remote event in replicated storage and add a script in ServerScriptService.

Put this in your localscript:

 script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

And add this into the script in ServerScriptService:

local mask = game.ReplicatedStorage.Mask
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)
	if player.Character:FindFirstChild("Mask") then
		player.Character.Mask:Destroy()
	else
		mask:Clone().Parent = player.Character
	end
end)
1 Like

1 Like

Actually this happened on the server script…

My bad, in the server script replace

game.ReplicatedStorage.RemoteEvent.OnClientEvent

with

game.ReplicatedStorage.RemoteEvent.OnServerEvent

Thats the same… fella check ur script.

You have to do the addaccessory in a server script so you could use a remote event to pass it on to a server script

Replace OnClientEvent with OnServerEvent. Not the same.
It was my mistake that I mixed them up with eachother in my script.

1 Like

It worked man thanks you are goated!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.