I’ve already racked my brains trying to resolve this error and I haven’t gotten anywhere. I don’t think it’s an error in my code but I wanted to be sure.
When I equip the sword and unequip it the first time everything is fine. However, the second time, it gives this error, and it doesn’t even make sense because this function is not used in the equip code.
When I reset I can use the sword once again, but then this error returns.
Play animation function:
function Weapon:PlayAnim(anim:Animation)
local trackAnim = Weapon.animController:LoadAnimation(anim)
trackAnim:Play()
return trackAnim
end
Equip Function
function Weapon:Equip(humanoidRootPart)
if Weapon.CanActions then
Weapon.CanActions = false
Weapon.Model = humanoidRootPart.Parent[Weapon.Name]
Weapon.animController = Weapon.Model.AnimationController
-- Animations:
Weapon.equipAnim = Weapon.Model.Animations:FindFirstChild("equip")
Weapon.unequipAnim = Weapon.Model.Animations:FindFirstChild("unequip")
Weapon.idleAnim = Weapon.Model.Animations:FindFirstChild("idle")
Weapon.blockAnim = Weapon.Model.Animations:FindFirstChild("block")
Weapon.idleBlockAnim = Weapon.Model.Animations:FindFirstChild("blockIdle")
Weapon.attackAnim01 = Weapon.Model.Animations:FindFirstChild("attack01")
Weapon.attackAnim02 = Weapon.Model.Animations:FindFirstChild("attack02")
Weapon.attackAnim03 = Weapon.Model.Animations:FindFirstChild("attack03")
-- Sounds
Weapon.mainSound = Weapon.Model.Sounds.equip
attackSound = Weapon.Model.Sounds.attack
Weapon.stabSound = Weapon.Model.Sounds.stab
Weapon.blockSound = Weapon.Model.Sounds.block
-- Equip Animation
local trackEquipAnim = Weapon.animController:LoadAnimation(Weapon.equipAnim)
trackEquipAnim:Play()
local childs = Weapon.Model:GetChildren()
-- Loop for make viewmodel visible(Animation loading to slow dibialducionaoius)
for i = 1, # childs, 1 do
if childs[i].ClassName == "MeshPart" and not ( childs[i].Name == "root") then
childs[i].Transparency = 0
end
end
--
spawn(function()
local weld = Instance.new("Weld")
weld.Parent = Weapon.Model.root
weld.Part0 = Weapon.Model.root
weld.Part1 = humanoidRootPart.Parent.UpperTorso
end)
-- Idle Anim
task.wait(0.5)
Weapon.mainSound:Play()
trackEquipAnim.Stopped:Wait()
local trackIdlepAnim = Weapon.animController:LoadAnimation(Weapon.idleAnim)
trackIdlepAnim:Play()
Weapon.CanActions = true
end
end
Unequip function:
function Weapon:Unequip()
if Weapon.CanActions == true then
Weapon.CanActions = false
for _,anim in pairs( Weapon.animController:GetPlayingAnimationTracks()) do
anim:Stop() -- To stop all animations(se não buga :\)
end
local anim = Weapon:PlayAnim(Weapon.unequipAnim)
task.wait(1)
Weapon.mainSound:Play()
anim.Stopped:Wait()
Weapon.CanActions = true
Weapon.Model:Destroy()
end
end
pls ignore the comments inside the code
Video: