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

Identifying First Person?

I'm wanting to do something once a player zoom in (to the max) for example, the player zoomned in to first person and it will print 'hi' ONCE. and if he zoom out nothing will change until he zoom in back again.

1 comment

0

There's nothing I could mind of as fast as you might need it, but here's the roblox wiki article for the Camera. http://wiki.roblox.com/index.php?title=API:Class/Camera

1 answer

You can achieve this effect using a combination of an input event and a distance check.

Note that this code will only work in a LocalScript, so place it somewhere a LocalScript can run.

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

uis.InputChanged:connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseWheel then
		--The user is scrolling in some way, so let's check the distance between their Camera and their Head.
		--After some testing, the 'first person' distance is .5 studs, exactly. But, it's likely to be a bit higher or a bit lower at any point, so it's better to check if it's less than slightly higher than .5.
		--Because fractional studs are so small, < .6 should work:
		if (player.Character.Head.CFrame.p - workspace.CurrentCamera.CFrame.p).magnitude < .6 then
			print("First person achieved!")
		end
	end
end)

The above code isn't perfect (it will print when you zoom out as well as in, and will continue to print if you 'zoom in' while already in first person), but should be a good starting point.

Given that I know you're new to ROBLOX scripting, take a look at wiki.roblox.com, and the Object Browser in Studio, to see the API you have available.

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