Im using a script that plays an animation when a player presses a key... but whenever they hold the key down and then click... it stops the animation for a split second. Is there a way to prevent this?
Script:
local p = game.Players.LocalPlayer
local anim = script.Animation
local serv = game:GetService("UserInputService")
local keyCodeW = Enum.KeyCode.W
local char = p.Character
if not p.Character then
repeat wait() until p.Character
end
local human = char:WaitForChild("Humanoid")
local newAnim = human:LoadAnimation(anim)
wait(5)
serv.InputBegan:Connect(function(key,processed)
if serv:IsKeyDown(keyCodeW) then
print("Starting animation!")
newAnim:Play()
end
end)
serv.InputEnded:Connect(function(key,processed)
if not serv:IsKeyDown(keyCodeW) then
newAnim:Stop()
end
end)

2 comments
That's because that's how your code is written. If the key is not == w then it stops the animation.
Clicking is a considered a key by the way if that's what you are confused about.