Hi I’m trying to make the player have a walk animation when they press W and when the W key is double tapped the animation changes alongside the walk speed. The script doesn’t work at all…
Neither am I getting any output that could help me fix the problem.
I tried adding prints to the script to see if the script was running yet still nothing.
-- Get the UserInputService to detect user input
local UIS = game:GetService("UserInputService")
-- Set the default field of view
local DefaultFOV = 70
-- Initialize the last time a key was pressed
local lastTime = tick()
-- Get the local player
local player = game.Players.LocalPlayer
-- Get the character of the local player
local char = game:GetService("Players").LocalPlayer.Character
-- Get the Humanoid object of the character
local hum = char:WaitForChild("Humanoid")
-- Variable to track if the character is running
local run = false
-- Load the "RunningAnim" animation for the character
local Track1 = hum:LoadAnimation(script:WaitForChild("RunningAnim"))
-- Load the "WalkingAnim" animation for the character
local Track2 = hum:LoadAnimation(script:WaitForChild("WalkingAnim"))
-- Connect a function to the InputBegan event of the UserInputService
UIS.InputBegan:Connect(function(input,gameprocessed)
-- Check if the pressed key is 'W'
if input.KeyCode == Enum.KeyCode.W then
-- Play the "WalkingAnim" animation
Track2:Play()
Track2:AdjustSpeed(1)
-- Print a message indicating that the 'W' key is pressed
print("W key pressed")
-- Get the current time
local now = tick()
-- Calculate the difference in time since the last key press
local difference = (now - lastTime)
-- Check if the time difference is less than or equal to 0.5 seconds
if difference <= 0.5 then
-- Print a message indicating that the time difference condition is met
print("Time difference condition met")
-- Set the run variable to true
run = true
-- Play the "RunningAnim" animation
Track1:Play()
-- Adjust the speed of the "RunningAnim" animation
Track1:AdjustSpeed(1)
-- Increase the walk speed of the character
hum.WalkSpeed = 80
-- Define properties for camera tweening
local properties = {FieldOfView = DefaultFOV + 10}
-- Define TweenInfo for camera tweening
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0.1)
-- Create a tween for camera movement
local T = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera,Info,properties)
-- Play the camera tween
T:Play()
end
end
end)