I have a punching script which pulls out fists when pressing a keybind, however, when I want to unequip the fists the animation track will not stop. I have attempted to debug this and it returns that it the animation is not playing as it should, but the player still holds his fists out. Here is my code:
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local fistsAnim = Instance.new("Animation")
fistsAnim.AnimationId = "http://www.roblox.com/asset/?id=ID"
local fistsAnimtrack = character.Humanoid.Animator:LoadAnimation(fistsAnim)
local punchAnim1 = Instance.new("Animation")
punchAnim1.AnimationId = "http://www.roblox.com/asset/?id=ID"
-- old = 16244185015
local punchAnimtrack1 = character.Humanoid.Animator:LoadAnimation(punchAnim1)
local punchAnim2 = Instance.new("Animation")
punchAnim2.AnimationId = "http://www.roblox.com/asset/?id=ID"
local punchAnimtrack2 = character.Humanoid.Animator:LoadAnimation(punchAnim2)
local damage = 5
local debounce = 0.3
local keybind = Enum.KeyCode.X
local canPunch = false
local fistsOut = false
UIS.InputBegan:Connect(function(input, _gameprocessed)
if input.KeyCode == keybind and not _gameprocessed then
if not fistsOut then
fistsOut = true
print("Fists out true, ", fistsOut)
fistsAnimtrack:Play()
canPunch = true
local punch = 0
UIS.InputBegan:Connect(function(input, _gameprocessed)
if fistsOut then
if input.UserInputType == Enum.UserInputType.MouseButton1 and not _gameprocessed then
if canPunch == true then
canPunch = false
if punch == 0 then
punch = 1
punchAnimtrack1:Play()
ReplicatedStorage.Events.Punch:FireServer(damage)
elseif punch == 1 then
punch = 0
punchAnimtrack2:Play()
ReplicatedStorage.Events.Punch:FireServer(damage)
end
wait(debounce)
canPunch = true
end
end
end
end)
else
fistsOut = false
canPunch = false
fistsAnimtrack:Stop()
print("Fists out false, ", fistsOut)
print(character.Humanoid:GetPlayingAnimationTracks())
print(fistsAnimtrack.IsPlaying)
end
end
end)