So, I’m making a sword.
And seems like the sword idle is broken.
My attack script:
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(player, damage, tool, charge, swing, hitId, lightId, heavyId, attackType)
local event
playSound(swing, tool)
local newHitboxRay = RaycastHitbox.new(tool.HitPart)
newHitboxRay.RaycastParams = RaycastParams.new()
newHitboxRay.RaycastParams.FilterDescendantsInstances = {player.Character}
newHitboxRay.RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
newHitboxRay.Visualizer = false
local lightAttack = Instance.new("Animation")
lightAttack.Name = "LightAttack"
lightAttack.Parent = game.Workspace
lightAttack.AnimationId = lightId
lightAttack = player.Character.Humanoid.Animator:LoadAnimation(lightAttack)
local heavyAttack = Instance.new("Animation")
heavyAttack.Name = "HeavyAttack"
heavyAttack.Parent = game.Workspace
heavyAttack.AnimationId = heavyId
heavyAttack = player.Character.Humanoid.Animator:LoadAnimation(heavyAttack)
local att0, att1 = tool.HitPart:FindFirstChild("Att0"), tool.HitPart:FindFirstChild("Att1")
local trail = Instance.new("Trail")
trail.Color = ColorSequence.new(Color3.new(255, 255, 255))
trail.Attachment0 = att0
trail.Attachment1 = att1
trail.Lifetime = 0.1
trail.Transparency = NumberSequence.new{
NumberSequenceKeypoint.new(0.0, 0.6),
NumberSequenceKeypoint.new(0.5, 0.85),
NumberSequenceKeypoint.new(1.0, 1),
}
trail.Parent = tool.HitPart
local chosen
if attackType == "LightAttack" then
chosen = lightAttack
else
chosen = heavyAttack
end
game.ReplicatedStorage.DecreaseStamina:Fire(player, charge) -- Firing bindable event to decrease player's stamina
newHitboxRay.OnHit:Connect(function(hit, humanoid)
print(hit)
humanoid:TakeDamage(damage)
playSound(hitId, tool)
newHitboxRay:HitStop()
end)
newHitboxRay:HitStart()
game.ReplicatedStorage.ChangeDebounce:Fire(player)
chosen:Play()
repeat wait() until chosen.IsPlaying == false
newHitboxRay:HitStop()
trail:Destroy()
end)
And boom!
This thing happens when I attack and then unequip the sword
Is there any solution?