Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my camera shift in running script is not working very well?

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = script.Parent.Humanoid
UserInputService = game:GetService("UserInputService")

humanoid.Running:Connect(function(speed)
UserInputService.InputBegan:Connect(function()
        if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and speed > 0 then
                humanoid.WalkSpeed = 32
for i = 1, 5 do
	print(speed)
	game.Workspace.CurrentCamera.FieldOfView  = (70 + (i * 2))
	wait()
end
else end
end)
 
UserInputService.InputEnded:Connect(function()
                humanoid.WalkSpeed = 16
for i = 1, 5 do
	game.Workspace.CurrentCamera.FieldOfView  = (80 - (i * 2))
	wait()
end
end)
end)

I don't want the camera to zoom if you are not walking. That is why I put humanoid.Running:Connect(function(speed) in the script. However, The camera will still zoom even if you are not walking. Please fix this

1 answer

✓ Accepted answer

UserInputService.InputEnded will fire if you release any key, it does not even check if you are walking or running, so if you let go of any key it will zoom (line 18-24)

This discussion is preserved as it was. New answers, comments, and votes are closed.