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

How to stop zooming out from the character when tool is being hold by him ?

How do i do it ? i have no idea if i do the minzoomdistance in player and max it will make it very buggy so what's the other way ?

Tool = script.Parent
player = game.Players.LocalPlayer
Char = player.Character

Max = player.CameraMaxZoomDistance

Tool.Equipped:connect(function()
	player.CameraMaxZoomDistance = 0.5
end)

Tool.Unequipped:connect(function()
	player.CameraMaxZoomDistance = Max
end)


2 comments

0

I'm using it currently for a project and it's not buggy for me. Show us the script that uses Max/Min Camera Zoom and we can help you fix it. I think I might already know the problem, but I need to see the script to be sure.

0

there

1 answer

✓ Accepted answer

Well,

Because you didn't explain what "buggy" means, I'm going to have to assume.

Testing this does exactly what you would expect it to do.

I'm assuming you want it to zoom the camera back out again once you Unequipped the tool. Luckily for you, there's a CameraMinZoomDistance!

Tool = script.Parent
player = game.Players.LocalPlayer
Char = player.Character
Max = player.CameraMaxZoomDistance

Tool.Equipped:connect(function()
	player.CameraMaxZoomDistance = 0.5
end)

Tool.Unequipped:connect(function()
	player.CameraMaxZoomDistance = Max
	player.CameraMinZoomDistance = 12
	player.CameraMinZoomDistance = 0.5
end)

Obviously this can be adjusted to not allow the player to zoom in or out as well by Setting camera max and min distance to the same.

Extra info,

You can get where the What the current camera zoom is by finding the magnitude of the Camera Position and the Local Player's Head position, like so,

-- Local Script
local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:wait()
local Head = char:WaitForChild("Head")
local cam = workspace.CurrentCamera

while wait() do
	print((cam.CFrame.p-Head.Position).Magnitude)-- Prints current Camera Zoom Distance
end

Good Luck!

I might have misunderstood the question, idk.

2 comments

0

finally, im learning something.

0

<3

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