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

Lock player's camera distance and unlock when click?

I made this script that locks the player's cam distance to 10 which is only to avoid zooming in and out by accident. How can I make it so when the player clicks again, it lets him/her use the scrolling to zoom in and out?

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
	player.CameraMaxZoomDistance = 10
end)

1 answer

✓ Accepted answer

You could set a variable defining if it was enabled or not, and change that based on the player click. Example:

local player = game.Players.LocalPlayer
local locked = false

script.Parent.MouseButton1Click:Connect(function(click)
	if locked == false then
		player.CameraMaxZoomDistance = 10
		locked = true
	elseif locked == true then
		player.CameraMaxZoomDistance = 128 -- This is game default, set this to whatever you want
		locked = false
	end
end)

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