Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script not working?

Asked by 10 years ago

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)

1 answer

Log in to vote
0
Answered by 10 years ago

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)

Ad

Answer this question