Okay so I made a sprint for my game, and I’m testing it and although the script works fine, the fov and the animation play while I am standing still which is not intended, and the fov and animation are aimed to be played when the player moves
this is the script so far and I dont understand wahts wrong since the game checks for if its processed
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local sprintFov = 80
local normalFov = 70
local sprintKey = Enum.KeyCode.LeftControl
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local sprintAnimation = script:WaitForChild("Sprint")
wait(1)
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:FindFirstChildOfClass("Animator")
local sprintAnimationTrack = animator:LoadAnimation(sprintAnimation)
local defaultSpeed = humanoid.WalkSpeed
local sprintSpeed = (humanoid.WalkSpeed*2)
local camera = workspace.CurrentCamera
local isSprinting = false
local function tweenFov(duration, fov)
local tween = tweenService:Create(camera, TweenInfo.new(duration, Enum.EasingStyle.Quad), {FieldOfView = fov})
tween:Play()
spawn(function()
tween.Completed:Wait()
tween:Destroy()
end)
end
local function beginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftControl then
player.Character.Humanoid.WalkSpeed = sprintSpeed
tweenFov(0.2, sprintFov)
sprintAnimationTrack = animator:LoadAnimation(sprintAnimation)
sprintAnimationTrack.Looped = true
sprintAnimationTrack:Play()
end
end
end
end
local function endSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftControl then
player.Character.Humanoid.WalkSpeed = defaultSpeed
sprintAnimationTrack.Looped = false
sprintAnimationTrack:Stop()
tweenFov(0.2, normalFov)
end
end
end
end
userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.