How to limit camera zoom?

robloxapp-20240703-1559438.wmv (1.8 MB)
Hello. I wrote a script to scroll the wheel. StudsY is the camera’s distance from the character. I want to make sure there is some kind of limitation. I’ll attach a video to make it clear what I mean.

uis.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseWheel then
if input.Position.Z > 0 then
StudsY -= 1
else
StudsY += 1
end
end
end)

1 Like

Just check if CameraScroll Y position is not higher and not smaller than min and max value, otherwise just dont run your function/code and e.t.c, in your script you need to check camera StudsY inside your condition.

1 Like

Is it possible for you to convert the video to mp4.

1 Like

You don’t have to write a script for this, go to StarterPlayer and change CameraMaxZoomDistance and CameraMinZoomDistance

1 Like

1 Like

I tried to edit, but the video weighs too much

True, this is the feature you need to use.

gotta gettttttttttttt characters

He’s writing custom camerazoom script

Fine. I wrote something like this

if StudsY >= 5 and StudsY <= 15 then
	if input.UserInputType == Enum.UserInputType.MouseWheel then
		if input.Position.Z > 0 then
			StudsY -= 1
		else
			StudsY += 1			
		end
	end
end

But because of this, if the StudsY variable reaches 15 or 5, the script stops working

Try to add print() on most of the parts of your script like print(“a”) etc it will help you narrow down what isn’t functional.

Why exactly do you need to get a character?

What are you even talking about? I gave you an idea that you can use to debug ur script, I never mentioned anything about characters.

if input.UserInputType == Enum.UserInputType.MouseWheel then
	if input.Position.Z > 0 then
		if StudsY >= 5  then
			StudsY -= 1
		end
	else
		if StudsY <= 15 then
			StudsY += 1
		end	
	end
end

you need to do it like that

1 Like

have you tried math.min() and math.max()?

something like

if input.UserInputType == Enum.UserInputType.MouseWheel then
		if input.Position.Z > 0 then
			StudsY = math.max(StudsY-1,5) --This won't get below 5
		else
			StudsY = math.min(StudsY+1,15) --This won't go above than 15			
		end
	end
1 Like

Thank you. It really works dsa

If it’s solved problem then mark as solution my solution, otherwise tell whats wrong

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.