I’m trying to change the players perspective with a key than change it back, like press the key and the camera zooms into lowest camera distance, press it again than it zooms back to the max camera distance. It changes the starterplayer max zoom distance but players distance in game.
Here’s my code:
local player = game.Players.LocalPlayer or game.Players.PlayerAdded.Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
function onKeyPressed(inputObject, gameProcessEvent)
if inputObject.KeyCode == Enum.KeyCode.V then
game.StarterPlayer.CameraMaxZoomDistance = 0.5
end
end
uis.InputBegan:Connect(onKeyPressed)
Hmm, well first is this script in a local Script? I fell that would run much better.
Now, from what i’m understanding, you can try this:
local Camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.V then
Camera.FieldOfView = 5
end
end)
UIS.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.V then
Camera.FieldOfView = 70
end
end)
Hope this helps you out. Reply if it doesn’t or I didn’t understand the situation correctly.
Edit: The Camera maximum zooming distance shouldn’t need to be modified since it’s the field of view thats increasing. Changing the field of view does give a “zooming” effect.
local Camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local Lock = false
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.V then
if Lock == false then
Camera.FieldOfView = 5
Lock = true
else
Camera.FieldOfView = 70
Lock = false
end
end
end)
Edit: You can also add a Debounce, to make a ‘cool down’ within the script
and if its a local script you do not need the or part you just need the game.Players.LocalPlayer
so basically there is a error on the first line (you should keep output open when coding)
if its a local script use this code:
local player = game.Players.LocalPlayer or game.Players.PlayerAdded.Wait()
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
function onKeyPressed(inputObject, gameProcessEvent)
if gameProcessEvent then return end
if inputObject.KeyCode == Enum.KeyCode.V then
game.StarterPlayer.CameraMaxZoomDistance = 0.5
end
end
uis.InputBegan:Connect(onKeyPressed)
Hmm that very weird. I tested the line of code I mentioned, and no it is not a mistake, since the code no longer works. hmm.
I also tested the .CameraMaxZoomDistance but it also doesn’t seem to work.
But I just spotted what was wrong so now I think I have your solution:
local Camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local Lock = false
local Player = game.Players.LocalPlayer
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.V then
if Lock == false then
Player.CameraMode = Enum.CameraMode.LockFirstPerson
Lock = true
else
Player.CameraMode = Enum.CameraMode.Classic
Player.CameraMinZoomDistance = --Number distance you want
Lock = false
end
end
end)
are you familiar with camera zoom speed? I made some tweaks and it works but I want an instant transition I know it has something to do with the zoom module in camera but have no clue what to edit.