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

How do I detect if a player goes into first person?

I want to print "Player is now in first person." every time the player goes into first person. How would I do this? I have checked developer.roblox.com, but it doesn't seem to have an event for going into first person.

Edit: After it detects that the player is in first person, how would I detect when the player leaves first person?

1 answer

✓ Accepted answer

You have to use magnitude which is the distance between parts. Make sure it's a LocalScript.

local function isFirstPerson()
	local camera = workspace.CurrentCamera
	local character = game:GetService("Players").LocalPlayer.Character or  game:GetService("Players").LocalPlayer.CharacterAdded
	if (character.Head.CFrame.p - camera.CFrame.p).magnitude < 1 then
		return true
	else
		return false
	end
end

while wait() do
	local isFirstPerson = isFirstPerson()
	
	if isFirstPerson == true then
		print("Player is now in first person.")
	end
end

The isFirstPerson() function returns true if the player is in first person.

4 comments

0

How do I detect if the player exist first person?

0

Would I use an elseif?

0

Just use "else".

0

ok, got it. thanks!

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