I have a sword that plays a hold animation when a player equips and and a attack animation when a player clicks, but when I add a hitbox, the player starts glitching out along with the tool. Both parts have can collide and anchored to false.
Script:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local tool = script.Parent
local hold = tool:FindFirstChild('Hold')
local attack = tool:FindFirstChild('Attack')
local animationtrack = char:WaitForChild('Humanoid').Animator:LoadAnimation(hold)
tool.Equipped:Connect(function()
animationtrack.Looped = true
animationtrack:Play()
end)
tool.Unequipped:Connect(function()
animationtrack:Stop()
end)
tool.Activated:Connect(function()
animationtrack:Stop()
local animationattack = char:WaitForChild('Humanoid').Animator:LoadAnimation(attack)
animationattack:Play()
wait(0.78)
local clone = game.ReplicatedStorage.SwordHitbox:Clone()
clone.Parent = tool
clone.CanCollide = false
clone.Anchored = false
clone.Transparency = 1
local weld = Instance.new('WeldConstraint', tool.Handle)
weld.Part0 = tool.Handle
weld.Part1 = clone
tool["Sword Swing Metal Heavy"]:Play()
animationattack.Stopped:Wait()
clone:Destroy()
animationtrack:Play()
end)
Make sure the hitbox has massless enabled in its properties. When a part with mass is held by the player it can weigh the character down and cause glitching; regardless of whether or not it’s invisible.
Programmatically, you could simply do clone.Massless = true.
Also, another note, you shouldn’t assign parents using the second argument of Instance.new(); it is deprecated and can lead to weird behavior (especially if they remove the feature).
Here is Roblox staff talking about not using the second argument: