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

How can I change the Player's zoom distance by touching a part?

Asked by 3 years ago

I don't know much about scripting but here's the script:

function onTouched(part)
     if part.Parent then
          local player = part.Parent:FindFirstChild("Humanoid")
        if player then
            player.CameraMaxZoomDistance = 15
            player.CameraMinZoomDistance = 15
            player.CharacterJumpPower = 28
          end           
     end
end
script.Parent.Touched:connect(onTouched)

What I'm trying to achieve is to make the player who touched it's zoom distance change, but the script appears to not be working.

0
i think you need to respawn the player before it works IBims1CoolesTim 17 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
  1. Your "player" variable would be an humanoid in this case, you would want to get the player from the character then set the zoom distance It should look something like this:
function onTouched(part)
    if part.Parent then
        local human = part.Parent:FindFirstChild("Humanoid")
        if human then
            local player = game.Players:GetPlayerFromCharacter(part.Parent)
            if player then

                player.CameraMaxZoomDistance = 15
                player.CameraMinZoomDistance = 15
                human.JumpPower = 28

            end


        end           
    end
end
script.Parent.Touched:connect(onTouched)

hope this helped!

0
Thanks for answering! It appeared to work, but I'm using scriptable camera in my game, in which it won't work. Is there a way to workaround this? BUMMER_Poo 9 — 3y
0
are you making a 2d game? if so, you can just set the cframe of the camera to be closer or farther depending on your needs sata5pa3da 286 — 3y
0
I'm new to cframe and don't know how to access it as a variable. How could I achieve this? BUMMER_Poo 9 — 3y
0
it basically contains multiple stuff like position, orientation, look vector, etc. You still didnt answer my question if you were making a 2d game sata5pa3da 286 — 3y
View all comments (5 more)
0
Sorry, yea its a 2d game. BUMMER_Poo 9 — 3y
0
you can just do: workspace.CurrentCamera.CFrame += Vector3.new(10,0,0) --you can change the value depending on where the player is facing sata5pa3da 286 — 3y
0
i cant help much without knowing what im dealing with, i hope i help a little tho sata5pa3da 286 — 3y
0
Thanks for helping, I'll accept your answer as I never specifically mentioned what the camera's type needed to be BUMMER_Poo 9 — 3y
0
thx, sorry i couldnt be of more help sata5pa3da 286 — 3y
Ad

Answer this question