Hello! I am currently making a lightsaber for my game and am having a problem with an animation. Here is a video of the problem:
As you see, when I try to go from blocking back to idle, the animation gets stuck and my character is stuck in a permanent position.
Here is the code for blocking:
if inputState == Enum.UserInputState.Begin then
local toolEquipped = character:FindFirstChildWhichIsA("Tool")
if toolEquipped then
if toolEquipped.Name == "Lightsaber" then
if ignited then
local hum = character:FindFirstChild("Humanoid")
local blocking = script.Parent.Blocking.Value
if blocking == false then
print("blocking")
if IdleAnim ~= nil then
IdleAnim:Stop()
end
local BlockingAnim = hum:LoadAnimation(script.Parent.Animations.Blocking)
BlockingAnim:Play()
script.Parent.Remotes.Block:FireServer()
end
end
end
end
elseif inputState == Enum.UserInputState.End then
local toolEquipped = character:FindFirstChildWhichIsA("Tool")
if toolEquipped then
if toolEquipped.Name == "Lightsaber" then
if ignited then
local hum = character:FindFirstChild("Humanoid")
local blocking = script.Parent.Blocking.Value
if blocking == true then
print("unblocking")
if BlockingAnim ~= nil then
BlockingAnim:Destroy()
end
if IdleAnim == nil then
IdleAnim = hum:LoadAnimation(script.Parent.Animations.Idle)
end
IdleAnim:Play()
script.Parent.Remotes.Unblock:FireServer()
end
end
end
end
end
Any help is appreciated.