Hello! I am currently making a fnaf fangame, and obviously, I have a camera system.
Please read the whole post to understand everything
Please take note this post is a bit long
Context
But for some context:
I have many things in the camera system (first floor, second floor, vent map).
Basically first floor and second have, well cameras where you can see what’s happening outside the player’s office. The vent map just gives you 2 maps, UIs, (of both floors) and the vent system, so if an enemy is in one of them, they will be “tracked”
Before, on each camera button, I had individual local scripts for getting the CameraSubject
. Now I am remaking lots of codes, then putting them in one script and asking the forum how could I improve. Well here I am!
I remade the camera scripts for the second floor, there are 2 cameras on it, cam09 and cam10
Before I remaded my changing camera code, cameras wouldn’t save, meaning let’s say, on the first floor, you are on cam03, then close them and open them back. The CameraSubject
will be the first one, the default one. And now I added that!
Now the remake is succesfull! But just to be sure I am asking the forum for anything that I can improve.
Now please be aware that the remade code will also be made for the first floor.
The code
So for avoiding any confusion, here is the layout of the second floor
(The first floor is the same, Parent
is an ImageLabel, buttons are TextButtons)
Now the code that changes cameras in between: (local script)
local cam = workspace.CurrentCamera
--Current Camera
local SFMap = script.Parent
--Second Floor Map
local SFFolder = game.Workspace.Cameras.SecondFloor
local Cam09 = SFFolder.CamPart09
local Cam10 = SFFolder.CamPart10
local function ChangingCam(Camera)
cam.CameraSubject = Camera
end
SFMap.Cam09.MouseButton1Click:Connect(function()
ChangingCam(Cam09)
end)
SFMap.Cam10.MouseButton1Click:Connect(function()
ChangingCam(Cam10)
end)
Now some people might be wondering how we remember which camera was choosen last, so here’s a layout:
The Value Current
is a NumberValue.
Now for the code for changing the NumberValue.Value
: (script)
local Current = game.Workspace.CurrentCam.SecondFloor.Current
local cam = workspace.CurrentCamera
--Current Camera
local SFMap = script.Parent
--Second Floor Map
local SFFolder = game.Workspace.Cameras.SecondFloor
local Cam09 = SFFolder.CamPart09
local Cam10 = SFFolder.CamPart10
function ChangeVal2(Value)
Current.Value = Value
print(Current.Value)
end
SFMap.Cam09.MouseButton1Click:Connect(function()
ChangeVal2(09)
end)
SFMap.Cam10.MouseButton1Click:Connect(function()
ChangeVal2(10)
end)
Now the code for when we go to the second floor and remembering which camera was last. (Default is 09): (script)
local cam = workspace.CurrentCamera
local Current = game.Workspace.CurrentCam.SecondFloor.Current
script.Parent.MouseButton1Down:connect(function()
--cam.CameraType = Enum.CameraType.Attach
if game.Workspace.CurrentCam.SecondFloor.Current.Value == 09 then
cam.CameraSubject = game.Workspace.Cameras.SecondFloor.CamPart09
elseif game.Workspace.CurrentCam.SecondFloor.Current.Value == 10 then
cam.CameraSubject = game.Workspace.Cameras.SecondFloor.CamPart10
end
end)
Is there any ways to improve my code?
If there’s any confusion or uncertainty, please tell me! I hope I didn’t forget anything or wasn’t clear enough.
Sorry if this was a bit long.
Anyways, thanks for reading