Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to limit the zooming out distance when player touches brick?

Asked by 3 years ago

Hello,

I am creating a maze in one of my games and I would like it if players weren't able to zoom out whilst doing it to cheat their way to the finish.

I took some code from an old post on here about limiting the camera zoom distance; https://scriptinghelpers.org/questions/44213/

I'm not sure if the code is outdated or if something else is wrong with my script, but any help would be hugely appreciated :)

local PlayerDebounce = {}

script.Parent.Touched:connect(function(hit)
    wait()
    local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
    if humanoid and not PlayerDebounce[hit.Parent] then
        PlayerDebounce[hit.Parent] = true

        wait(0.2)
        game:GetService("Players").LocalPlayer.CameraMaxZoomDistance = 1
        game:GetService("Players").LocalPlayer.CameraMinZoomDistance = 1
        wait(0.5)

        PlayerDebounce[hit.Parent] = nil
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Well, I'm not sure what you want to achieve exactly

But if you want to change the player's max zoom distance when they touch a brick, you can use this

----- Customize -----

local MaxZoom = 1 -- Set this number to whatever max zoom distance you want

----- End -----


local brick = script.Parent

function touched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local char = hit.Parent
        local plr = game.Players:GetPlayerFromCharacter(char)
        plr.CameraMaxZoomDistance = MaxZoom
    end
end

brick.Touched:Connect(touched)
Ad

Answer this question