The script below is localscript.
Sprinting script works fine. but the problem is print("run") will print run multiple time when I only want it to print one time. and game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) Will work whenever a key(mouse click and other any keyboard key) is clicked. Please fix this.
local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local humanoid = Char:WaitForChild("Humanoid") -- Do not use script.Parent.Humanoid, use Char:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local Running = false
UserInputService.InputBegan:Connect(function(Input, gameProcessed)
if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and not gameProcessed then
Running = true
humanoid.WalkSpeed = 32
print("run")
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
wait()
end
end
end)
UserInputService.InputEnded:Connect(function(Input, gameProcessed)
if Input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
Running = false
humanoid.WalkSpeed = 16
if Running == false then
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
wait()
end
end
end
end)

1 comment
For 2 seconds I thought you put "pun intended", but it just says "inputended"