Hello Dev’s,
Today I ran in to a problem when making a running animation for my game. I made a running animation to play when you clicked (W) two times. I have the script to allow the speed to happen when the button is clicked but I don’t know how I can add in the script to have the animation play when I press the (W) key twice. I would love any help on this matter, Thanks again!
local UIS = game:GetService("UserInputService")
local DefaultFOV = 70
local lastTime = tick()
local char = game:GetService("Players").LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")
UIS.InputBegan:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
local now = tick()
local difference = (now - lastTime)
if difference <= 0.5 then
if hum.WalkSpeed < 11 then
print("running")
hum.WalkSpeed = 35
local properties = {FieldOfView = DefaultFOV + 15}
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
T:Play()
end
end
lastTime = tick()
end
end)
UIS.InputEnded:Connect(function(input,gameprocessed)
if input.KeyCode == Enum.KeyCode.W then
print("running")
hum.WalkSpeed = 10
local properties = {FieldOfView = DefaultFOV}
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
T:Play()
end
end)
hum.Died:Connect(function()
game.Workspace.Camera.FieldOfView = DefaultFOV
hum.WalkSpeed = 10
script.Disabled = true
end)
The code here allows me to increase my walk speed when the (W) key is pressed 2 times, but I want to add in where it plays a animation as well, any help would be greatly appreciated!