As of now, I’m tackling a Metal Gear Rising-esque weapons system. Starting off with equipping/unequipping the blade. However, the equipped run/idle animation continues to play AFTER the weapon has been unequipped.
I have looked through posts regarding bugs around stopping Animations. I’ve tried ipairs, and stopping it using the same Humanoid function in the Unequip statement. Oh and by the way, the LocalScript goes in ‘StarterPack’
--//Service Variables\\--
local UserInputService = game:GetService("UserInputService")
local Debounce = false
--//Replicated Storage\\--
local Weapons_Folder = game.ReplicatedStorage:WaitForChild("Weapons")
local WPChar_Folder = Weapons_Folder:WaitForChild("Raiden")
--//Animation Folder Variables\\--
local Animations_Folder = script:WaitForChild("Animations")
local EquipAnim_Track = Animations_Folder:WaitForChild("Equip")
local SwordIdle_01_Track = Animations_Folder:WaitForChild("SwordIdle_01")
local SwordIdle_02_Track = Animations_Folder:WaitForChild("SwordIdle_02")
--//Player & Character Variables\\--
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local LowerTorso, UpperTorso = Character:WaitForChild("LowerTorso"), Character:WaitForChild("UpperTorso")
local Equip_Value = Instance.new("BoolValue", Character)
Equip_Value.Value = false
Equip_Value.Name = "Equip"
--//Animation Variables\\--
local EquipAnim = Humanoid:LoadAnimation(EquipAnim_Track)
local SwordIdle_01 = Humanoid:LoadAnimation(SwordIdle_01_Track)
local SwordIdle_02 = Humanoid:LoadAnimation(SwordIdle_02_Track)
--Main
UserInputService.InputBegan:Connect(function(Input, GPE)
if not Debounce then --To prevent the player from spamming
Debounce = true
--_HF Blade_--
if Input.KeyCode == Enum.KeyCode.One and not GPE then
if Equip_Value.Value == false then
Equip_Value.Value = true
EquipAnim:Play()
Character.Sheath.HFBlade_Sheathed.Transparency = 1
local WP_HFBlade = WPChar_Folder:WaitForChild("HFBlade"):Clone()
WP_HFBlade.Parent = Character
WP_HFBlade.CFrame = Character.RightHand.CFrame * CFrame.new(-0.257, -0.158, -1.55)
local Weld = Instance.new("ManualWeld")
Weld.Part0 = Character:WaitForChild("RightHand")
Weld.Part1 = WP_HFBlade
Weld.C0 = Weld.Part0.CFrame:ToObjectSpace(Weld.Part1.CFrame)
Weld.Parent = Weld.Part1
RootPart:WaitForChild("Blade_Equip"):Play()
--Equipped Idle
SwordIdle_01:Play()
Humanoid.Running:Connect(function(Speed)
local State = Humanoid:GetState()
if (State ~=Enum.HumanoidStateType.Freefall) and (State ~=Enum.HumanoidStateType.Jumping) then
if Speed == 0 then
SwordIdle_01:Play()
if SwordIdle_02.IsPlaying then
SwordIdle_02:Stop()
end
else
SwordIdle_01:Stop()
SwordIdle_02:Play()
end
end
end)
elseif Equip_Value.Value == true then
SwordIdle_01:Stop()
SwordIdle_02:Stop()
Equip_Value.Value = false
EquipAnim:Play(0.100000001, 1, -1) --Reversed Animation Values: (Default Fadetime, Default Weight, Negative Speed)
RootPart:WaitForChild("Blade_Unequip"):Play()
wait(0.25)
Character.Sheath.HFBlade_Sheathed.Transparency = 0
local WP_HFBlade = Character:FindFirstChild("HFBlade")
WP_HFBlade:Destroy()
end
end
wait(0.1)
Debounce = false
end
end)
For your information, here is what the animations are for SworldIdle.