In my tool I've got a local script which runs an animation when holding the tool and the key is pressed. In the tool there is the Animation folder with the animations and there is the handle and local script. The Problem I have is when I press the key the animation plays but when I click the key again it doesn't stop playing.
Here is my script
local player = script.Parent.Parent.Parent --Gets the player if this is a regular tool in starterpack
local character = player.Character or player.CharacterAdded:Wait()
local tool = script.Parent
local mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")
-- Bools --
local toolon = false
local isblocking = false
-- Animations --
local Block = script.Parent.Animations.Block
local animationTrack
tool.Equipped:Connect(function()
toolon = true
end)
tool.Unequipped:Connect(function()
toolon = false
end)
UserInputService.InputBegan:connect(function(i,g)
if i.UserInputType == Enum.UserInputType.Keyboard then
if i.KeyCode == Enum.KeyCode.E and toolon == true and isblocking == false then
animationTrack = character:WaitForChild("Humanoid"):LoadAnimation(Block)
animationTrack:Play()
print("Block Is On")
isblocking = true
end
end
end)
UserInputService.InputBegan:connect(function(i,g)
if i.UserInputType == Enum.UserInputType.Keyboard then
if i.KeyCode == Enum.KeyCode.E and toolon == true and isblocking == true then
animationTrack:Stop()
print("Block Is Off")
isblocking = false
end
end
end)
UPDATE: I've edited the code and changed it but it still doesn't work, Here is the new gif https://gyazo.com/985aef884e981d7318ce9fbd149f5757 Here is the new Rbxl https://mega.nz/file/nNxRTZRB#N_XZwyc8_QxjP0BQZdjCxdjxI6a_sPOCHEz_7JViynU

3 comments
When you created your animation, did you save it on Looped? If so, this could be your problem.
I saved it on loop so it wouldn't end until the E key was pressed again.
I've updated the question. With the new code and gif but still doesn't work