I’m trying to have the player be able equip/unequip swords but whenever they equip a sword for the second time it parents the sword Accessory to the HumanoidRootPart instead. I’ve tried explicitally setting the constraints/welds but whenever I parent it to the character the sword automatically gets AccessoryWelds.
function Swords.EquipWeapon(char: Model, weapon: Accessory)
local clone = weapon:Clone()
-- universal name for all weapons
clone.Name = "Weapon"
-- disable slash
for _, emitter in pairs(clone.Handle.SwordSlash:GetChildren()) do
emitter.Enabled = false
end
for _, emitter in pairs(clone.Handle.Parry:GetChildren()) do
emitter.Enabled = false
end
-- sword behavior & interaction script
local swordScript = ServerStorage.Scripts.WeaponInteraction:Clone()
swordScript.Parent = clone
swordScript.Enabled = true
-- move to character
char.Humanoid:AddAccessory(clone)
-- move slash to char
clone.Handle.SwordSlash.Parent = char.HumanoidRootPart
clone.Handle.Parry.Parent = char.HumanoidRootPart
end
First time
Every other time
Honestly using this function most of the time is overkill and parenting accessory manually to the character is good enough (it will handle welds so dw)
local WeaponInteraction:Script--[[i assume this is the sword script?]] = ServerStorage.Scripts.WeaponInteraction
local Clone = game.Clone::(sample:Instance)->Instance
local GetChildren = game.GetChildren::(ins:Instance)->{Instance}
function Swords.EquipWeapon(char: Model, weapon: Accessory):()
local HumanoidRootPart:BasePart = char.HumanoidRootPart::BasePart
local clone = Clone(weapon)
-- universal name for all weapons
clone.Name = "Weapon"
-- disable slash
for _, emitter in GetChildren(clone.Handle.SwordSlash) do
emitter.Enabled = false
end
for _, emitter in GetChildren(clone.Handle.Parry) do
emitter.Enabled = false
end
-- sword behavior & interaction script
local swordScript = Instance.fromExisting(WeaponInteraction)
swordScript.Parent = clone
swordScript.Enabled = true
-- move to character
clone.Parent = char
-- move slash to char
clone.Handle.SwordSlash.Parent = HumanoidRootPart
clone.Handle.Parry.Parent = HumanoidRootPart
end
I had to apply shizo optimization since yk very tempting.
Still doesn’t work, I actually had tried this before. It correctly welds it to the RightGripAttachment the first time you equip it but after that it will permanently ignore it and just put it in the center of your HRP
I guess i know why it is heppening
You assidantly disable Weld in the loop:
for _, emitter in GetChildren(clone.Handle.SwordSlash) do
emitter.Enabled = false
end
for _, emitter in GetChildren(clone.Handle.Parry) do
emitter.Enabled = false
end
Try checking if weld is enabled to prove/disprove my theory.
Nah there are only particleemitters that are parented to those
Weld is getting automatically created to hold Handle in place.
Try looking in the explorer where Weld is attached to/if its even enabled.