So basically, I have a plane model right?
When I zoom in I want the cockpit to be visible, but when I'm in first person the model becomes invisible.
I think what you want to do is this,
when it zoom in, create a screenGUI that cover the whole screen, you design and display a 2D image of cockpit, in the middle of the screen gui, you make a part of area transparent, that is your window.
when you exit the first person mode, just hide the screen gui
You can try checking the distance between client's CurrentCamera and the LocalPlayer character's head. When the magnitude reaches under a certain minimum, the model should become invisible.
--LocalScript local plr = game.Players.LocalPlayer --Get the LocalPlayer local cam = workspace.CurrentCamera --Get the client's camera. local char = plr.Character or plr.CharacterAdded:Wait() --waits for their character. local head = char:WaitForChild("Head") --since Head is the focus of our CurrentCamera. local justFirstPerson = false --this will become handy later. --Create a new function to bind to render step. local function becomeInvisible() --We will calculate the distance between the client's Camera and their character's head. --distance = (startpos - endpos).Magnitude local distance = (cam.CFrame.p - head.CFrame.p).Magnitude --Now, there are two things to check: --Firstly, the distance between the camera and player's head should be below a certain limit, like 1 for example, in order to take action. --Secondly, check if the player's CameraMode is locked to first person. Now, this property won't change if the player zoomed in to activate first person mode, but rather when it is requested to change manually or by a running thread, such as a script. We don't know if it's going to be changed or not, so we have to check that too. if justFirstPerson == false and (distance <= 1 or plr.CameraMode == Enum.CameraMode.LockFirstPerson) then justFirstPerson = true --This will prevent the function from running consecutively. --Do your thing, like indexing the BasePart descendants of the Model and set its transparency to 1. elseif justFirstPerson then --Remember to revert the changes made during first person when player is no longer in the mode. justFirstPerson = false end end) game:GetService("RunService"):BindToRenderStep("hideModelsOnFP", 1, becomeInvisible) --[[ Parameters of BindToRenderStep: (name, renderPriority, functionToBind) name: Name of the binded function, can be used to unbind the binded function. renderPriority: an interger that determines when will the binded function will be called during when a frame is rendered. The more, the sooner the funciton will be ran. functionToBind: the requested function to run during a render step. ]]
Locally set the model's parent to the player's Character. If you notice, you'll see that when the player is in first person, their character turns invisible. It's one of the functionalities of ROBLOX.
Be careful if you do this. When the player dies, if Players.CharacterAutoLoads
property is set to true, their character will be destroyed after an interval relative to Players.RespawnTime
or when Player:LoadCharacter()
is called. It won't disappear in the server though, so you can replicate the model to the client once the player respawns, or before the character respawns, as long as their Character model is still there, and the part(s) of the Model is not owned by the player through SetNetworkOwner()
.
You should do further research for this. If I'm wrong, or if my solution is not efficient, please give me some feedbacks! c: