I want to make a script to hide/remove a high quantity of objects to decrease the lag, but I don't know if there is a way to do that. I don't know if putting these objects clientside in Lighting or ServerStorage will do the trick I need. So can someone please tell me if hiding objects in Lighting or ServerStorage is what I should do or if there is a better way.
For really big games, it's worth looking at StreamingEnabled, which basically loads and unloads parts of the game for players depending on their location, the downside of it is that you have to use :WaitForChild() a lot more since some assets may not be loaded in.
Yes! ServerStorage is the best way to do it as it is the "storage" of the game, while lighting may still operate scripts, The ServerStorage doesn't do that. Benefits of the server storage: The Objects are not drawn, so they reduce lag, scrips do not operate, so they do not take up power. I hope it helps!
There is a built in way to do this by using Camera.Focus. It basically prioritizes what to show in full quality based on where the focus currently is. By default, Camera.Focus is always on the Camera.Subject, however if you change the default camera scripts, you can control where the focus is via scripting. So to control the Camera.Focus, you need to set the camera type to scriptable, and you need to override the default Camera scripts. And also, to update it every frame, you can use BindToRenderStep rather than having a while true loop.
So for instance, if you have an fps game, and you want to unrender most of the objects directly behind the player, you can set the focus to be downrange of the player, so that the game renders everything in front of them to what their graphics quality is set at, but leaves out all the lighting and graphics changes behind them.
You can do the same with a 3rd person game, it just becomes a bit more difficult in that you need to use a bit more math when setting the focus in relation to the camera instead of humanoid root part of the 1st person method.
Here's an example of focus following the point in 3D space that the mouse is pointing at:
local UserInputService = game:GetService("UserInputService") UserInputService.InputChanged:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.MouseMovement then local ray1 = Camera:ScreenPointToRay(input.Position.X, input.Position.Y, 0)--creates a unit ray towards the mouse (ray with a magnitude of 1) local ray = Ray.new(ray1.Origin,ray1.Direction * 1000)--takes the original ray and multiplies the magnitude by 1000 local part, hitPos = workspace:FindPartOnRayWithIgnoreList(ray,character)--if there is an intersection before 1000 studs, it gives the position local Focus = CFrame.new(hitPos, --placed at the position in 3D space the mouse is pointing at ray.Origin) --facing the camera * CFrame.Angles(0,math.rad(180),0) --flips it around 180 degrees so it is facing towards the mouse Camera.Focus = Focus print("Mouse moved, Focus is now: "..Focus.Position.X,Focus.Position.Y,Focus.Position.Z) end end)
Just click view source on the code block to see the comments better, I've explained what is going on line by line.
I also use the UserInputService rather than render stepped here because if you want it to follow the mouse, then you would want to save some performance by not having it shoot rays every frame if you don't have to.