This is an in game script that runs an animation when the f key is down and stops when it is up.
player = game:GetService("Players").LocalPlayer char = player.Character mouse = player:GetMouse() local hum = char:FindFirstChild("Humanoid") local anim = Instance.new("Animation",char) anim.AnimationId = "http://www.roblox.com/asset?id=149359445" anim.Name = "Animation" mouse.KeyDown:connect(function(key) if key:lower() == "f" then animation = hum:LoadAnimation(char.anim) animation:Play() end end) mouse.KeyUp:connect(function(key) if key:lower() == "f" then animation:Stop() end end)
Try this. You only called the animation variable in the KeyDown event so it will only work in the KeyDown event.
player = game:GetService("Players").LocalPlayer char = player.Character mouse = player:GetMouse() local hum = char:FindFirstChild("Humanoid") local anim = Instance.new("Animation",char) anim.AnimationId = "http://www.roblox.com/asset?id=149359445" anim.Name = "Animation" local animation = hum:LoadAnimation(anim) mouse.KeyDown:connect(function(key) if key:lower() == "f" then animation:Play() end end) mouse.KeyUp:connect(function(key) if key:lower() == "f" then animation:Stop() end end)