My script where you press shift to run wont work? Please fix.
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed) if input.KeyCode == Enum.KeyCode.LeftShift then for i = 1,16 do wait() game.Workspace.camera.FieldOfView = game.Workspace.Camera.FieldOfView + 1.6 game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1 end end end) game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed) if input.KeyCode == Enum.KeyCode.LeftShift then for i = 1,16 do wait() game.Workspace.Camera.FieldOfView = game.Workspace.Camera.FieldOfView - 1.6 game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1 end end end) game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function() game.Workspace.Camera.FieldOfView = 70 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 script.Disabled = true end)
Your problem seems to be on line 5:
game.Workspace.camera.FieldOfView = game.Workspace.Camera.FieldOfView + 1.6
You've spelt Camera
as camera
, yet camera
doesn't exist according to what you said in the comments. Lua is case sensitive, so if capitalisation is off in some places it might not work. If you spell a name incorrectly it won't work.
Additionally, your code can be cleaned up. You use two for loops, when this could be put in a function and you call that function instead of writing duplicate loops:
local camera = workspace.CurrentCamera -- storing the local player's current camera in a variable local function change_fov(number) for i = 1, 16 do wait() camera.FieldOfView = camera.FieldOfView + number end end
And whenever you need to change the field of view you'd call change_fov
with an argument of 1.6
or -1.6
like so:
change_fov(1.6) -- or -- change_fov(-1.6) -- Call the function when is it appropriate to do so.
I also recommend that you have a variable for the local player as you were using that often as well. Also, you don't need to WaitForChild
on the same object more than once, if the humanoid didn't exist at first, WaitForChild
yielded (paused) until the humanoid was found.
And finally, RBXScriptSignal:connect()
is deprecated, use RBXScriptSignal:Connect()
.