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

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

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.

1 comment

0

i think you need to respawn the player before it works

1 answer

✓ Accepted answer
  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!

9 comments

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?

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

0

I'm new to cframe and don't know how to access it as a variable. How could I achieve this?

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

0

Sorry, yea its a 2d game.

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

0

i cant help much without knowing what im dealing with, i hope i help a little tho

0

Thanks for helping, I'll accept your answer as I never specifically mentioned what the camera's type needed to be

0

thx, sorry i couldnt be of more help

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