Changing Accessory Type with code

Hello DevForum! Long time no see. To quickly get into my issue, I have no idea how to change the AccessoryType of this vest! I want it to attach to the torso by making the AccessoryType Front but I don’t know how to achieve this. Much appreciated, Snale.

local tool=script.Parent
local handle=tool.Handle

local remotefunction=tool.RemoteFunction
local debris=game:GetService("Debris")

function remotefunction.OnServerInvoke(player,command,value)
	if command=="protect" then
		if value[2] then
			local currentvest=value[1]:FindFirstChild("VestArmour")
			if currentvest then
				currentvest:Destroy()
			end
			local vest=Instance.new("Accessory")
			vest.Name="VestArmour"
			local handle=handle:Clone()
			handle.Parent=vest
			vest.AttachmentPos=Vector3.new(0,0,0)
			vest.Parent=value[1]
			local ratio=value[2].Health/value[2].MaxHealth
			value[2].MaxHealth=100+value[3]
			value[2].Health=(100+value[3])*ratio
			
			
			tool:Destroy(function()
				
			end)
		end
	end
end

When you say change the accessory type, do you mean the property or actual positioning?

If the former,

accessory.AccessoryType = Enum.AccessoryType.Front

If the latter, you need to use an attachment called the name of the attachment you want to attach your accessory. For example,


This will weld the accessory to the BodyFrontAttachment of the dummy

image

You can change the positioning of the attachment inside your accessory and it will maintain the offset when applying it to the character.

so should the script look like this now?

local tool=script.Parent
local handle=tool.Handle

local remotefunction=tool.RemoteFunction
local debris=game:GetService("Debris")

function remotefunction.OnServerInvoke(player,command,value)
	if command=="protect" then
		if value[2] then
			local currentvest=value[1]:FindFirstChild("VestArmour")
			if currentvest then
				currentvest:Destroy()
			end
			local vest=Instance.new("Accessory")
			vest.AccessoryType = Enum.AccessoryType.Front
			vest.Name="VestArmour"
			local handle=handle:Clone()
			handle.Parent=vest
			vest.AttachmentPos=Vector3.new(0,0,0)
			vest.Parent=value[1]
			local ratio=value[2].Health/value[2].MaxHealth
			value[2].MaxHealth=100+value[3]
			value[2].Health=(100+value[3])*ratio
			
			
			tool:Destroy(function()
				
			end)
		end
	end
end