Need Part to force first person

I want to make it so inside of the non-collision part forces you into first person and doesn’t let you zoom back out, I have no scripting experience and I tried assistant but it didn’t work.

Does anybody have an example, video (Best option, visual learner), or idea how to help? Thank you.

You could make an event in the starterPlayer called ZoomEvent for when it zooms, and in the part you could put this:


script.Parent.Touched:Connect(function(part)
     local human = part.Parent:FindFirstChild("Humanoid")
     if human then
         if human.Parent:FindFirstChild("ZoomEvent") then
               human.Parent.ZoomEvent:FireClient(game.Players:GetCharacterFromPlayer(part.Parent))
         end
     end
)

…and in a localScript in StarterPlayerScripts you could put this:

local player = game.Players.LocalPlayer
local zoomEvent = player.ZoomEvent

zoomEvent.OnClientEvent:Connect(function()
     player.CameraMode = Enum.CameraMode.LockFirstPerson
end)

I believe this will work.

Placed the event inside of starterPlayer
and all it came up with is

ZoomEvent is not a valid member of Player “Players.Zack997685”

The error came from the Local Script

try putting it in starterPlayerScripts

Did not work, same error.
I am using RemoteEvent if that helps at all.

try using

player:WaitForChild("ZoomEvent")

Where should I place that?
Like what script and where in the script.

So when if you touch a part you get locked in First Person right?

script.Parent.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.CameraMode = Enum.CameraMode.LockFirstPerson
	end
end)

Put this in the part that you want to be collided with.

Are you able to edit this so when your out of the part it allows you to zoom out or it zooms you back out? If so then this is actually perfect and exactly what I need, Thank you.

you mean when your not touching the part anymore it zooms out

Yes that is exactly what I meant

script.Parent.TouchEnded:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.CameraMode = Enum.CameraMode.Classic
	end
end)
script.Parent.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.CameraMode = Enum.CameraMode.LockFirstPerson
	end
end)

script.Parent.TouchEnded:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		player.CameraMode = Enum.CameraMode.Classic
		player.CameraMinZoomDistance = 15
		wait(0.05)
		player.CameraMinZoomDistance = 0
	end
end)

Badly scripted but it works, put this in the part and it will work!

1 Like

Thank you and Domo for the help :saluting_face:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.