Hey, I’ve encountered an issue while trying to stop an idle animation, I’m using a ModuleScript as the main code for my katana, and when the unequip event is fired I would need to manually stop the animation, but that doesn’t work correctly and I would require some help.
The code is written below.
local module = {}
function foundkatanatool(char)
wait(.1)
local tool = char:FindFirstChildWhichIsA("Tool")
if tool then
local typ = tool:FindFirstChild("Type")
if typ and typ.ClassName == "StringValue" and typ.Value == "Sword" then
return true
end
end
end
module.EquipNichirin = function(character)
local model = character:FindFirstChild("SwordModel")
if model and model:IsA("Model") and character:FindFirstChild("Humanoid") then
local anim = character.Humanoid:LoadAnimation(script.Idle)
anim:Play()
if character.EquippedKatana.Value == false then
character.HumanoidRootPart.UnSheathe:Play()
local unsheatheanim = character.Humanoid:LoadAnimation(script.UnSheathe)
unsheatheanim:Play()
unsheatheanim:AdjustSpeed(.5)
end
character.EquippedKatana.Value = true
local weld = model.Handle:FindFirstChild("HandleWeld")
if weld then
weld.Part0 = character:FindFirstChild("Right Arm")
weld.C0 = CFrame.new(0, -1, 0) * CFrame.Angles(math.rad(270),math.rad(180),math.rad(90)) * CFrame.Angles(0, math.rad(90), 0)
end
end
end
module.UnequipNichirin = function(character)
local model = character:FindFirstChild("SwordModel")
if model and model:IsA("Model") and not foundkatanatool(character) and character:FindFirstChild("Humanoid") then
local anim = character.Humanoid:LoadAnimation(script.Idle)
wait()
anim:Stop()
character.HumanoidRootPart.Sheathe:Play()
character.EquippedKatana.Value = false
local weld = model.Handle:FindFirstChild("HandleWeld")
if weld then
delay(.12,function()
if not foundkatanatool(character) then
weld.Part0 = character:WaitForChild("Torso")
weld.C0 = CFrame.new(-1, -.1, -1.2) * CFrame.Angles(math.rad(200),math.rad(180),math.rad(90))
end
end)
end
end
end