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

How to fix Min/Max zoom distance change?

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	if gameProcessedEvent and inputObject.KeyCode == Enum.KeyCode.T then
		if toggle == true then
			humanoid.CameraOffset = Vector3.new(0,0,-1)
			player.CameraMaxZoomDistance = 0.5
			player.CameraMinZoomDistance = 0.5
			toggle = false
		else
			humanoid.CameraOffset = Vector3.new(0,0,0)
			player.CameraMaxZoomDistance = 12
			player.CameraMinZoomDistance = 6
			toggle = true
		end
	end
end)

This script should switch you to the first person and 3rd person changing min and max zoom distance to 0.5/0.5 (first person) or 12/6 (third person) but for some reason when I test it and try to switch min/max zoom distance, it changes min zoom distance to 6 only and not 0.5

1 comment

0

you are using a game processed event, that'll return a constant value so it'll keep on updating forcing it to be stuck at 6. Instead replace gameProcessedEvent with if key == Enum.UserInputState.Begin

1 answer

✓ Accepted answer

Hello, SuAkihiro!

In your code, the action would only happen if player is typing somewere eg. chat, what I think is not what you want, so I changed it to check if player is not chatting:

local toggle = true -- Set your variable before everything runs

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    -- instead of if gameProcessedEvent then, you should use if not gameProcessedEvent then
    if not gameProcessedEvent and inputObject.KeyCode == Enum.KeyCode.T then
        if toggle == true then
            humanoid.CameraOffset = Vector3.new(0,0,-1)
            player.CameraMaxZoomDistance = 0.5
            player.CameraMinZoomDistance = 0.5
            toggle = false
        else
            humanoid.CameraOffset = Vector3.new(0,0,0)
            player.CameraMaxZoomDistance = 12
            player.CameraMinZoomDistance = 6
            toggle = true
        end
    end
end)

If this fixes your issue, please mark the answer as accepted

1 comment

0

I know that it works like that but for some reason in my game, if I use "not gameProcessedEvent" it will work only in chat or textbox when just "gameProcessedEvent" will work if it is not chat or textbox, anyways I fixed that thing already, you didn't helped me but I'll mark it as answered anyways

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