Draw Distance? - Help with scripting a constantly updating draw distance script

Hi, I would like to make a script in roblox studio that turns off all shadows of all objects that are far away from the player, I’ve successfully scripted this… sort of, I’m using a while true do loop and get descendants, I do NOT run the Get:Decendants code inside of the while loop, that would crash my game. So the code works but lowers my fps by more than 50%. Is there a way to code a draw distance script that improves performance rather than destroys it. Also is there any secret performance script that anybody knows of that boost’s fps well? Lol, if so please let me know. Or just help with my current script XD:
(I deleted the script, but it went something like this):
workspace get descentdants
for pair blah blah blah get decendants
decendant1 = decendant – creating a global varible
end
while true do
if player.Character.Hrp.Position - decendant blah blah . magnitude greater than blah blah blah then
descendant.CastShadow = false
else
descendant blah blah = true
wait(1)
end

Instead of trying to disable shadows by distance, try using ROBLOX’s streaming enabled, or disable global shadows in lighting.

Trying to calculate the distance between the part and camera for every single part can lower your frame rate rather than increase it.

(depending on the update rate and also amount of parts)

I’d like to make my game look good, and already have streaming enabled on, my game is a city and I’d like to see the city lights from a distance so I don’t want the buildings to disappear or anything either, thanks for your reply though :slight_smile:

Roblox automatically disables Shadows on distance as far as I know. However, Disabling shadows from lights can be a good idea. I came up with this:

game:GetService("RunService").RenderStepped:Connect(function()
	for i, light in pairs(workspace:GetDescendants()) do
		if light.ClassName == "PointLight" or light.ClassName == "SurfaceLight" or light.ClassName == "SpotLight" then
			if (light.Parent.Position - game.Players.LocalPlayer.Character.Head.Position).Magnitude <= 250 then
				light.Shadows = true
			else
				light.Shadows = false
			end
		end
	end
end)

It does the job, but its very unoptimized. Still haven’t found a solution to run it only like half of FPS, not every frame. Hope this somehow helps! :wink:

2 Likes

With the power of Serialization, this is possible. You want to limit the load on the client’s device first and foremost.

The Idea Of Serialization ← starmaq’s forum post

When the game starts, it’s a hit or miss on what
server you’re given. You could get a higher performance
server, or a very low performing server.

Server capacity is extremely finite, and anything
running on the client’s computer is to be treated
the same, because there’s no telling what kind of
device or performance the clients will have.
The entire game has to run with as little data as
possible. If you can limit your data enough to have a functioning game, there’s more headroom for optimization and customization; this is where Serialization comes into play the most.

There’s multiple ways to calculate how the game disables shadows. You’re looking for the method that applies to your game the best.

One example is using a screen-space-chunk relationship. You have your Camera, and by using something like WorldToViewportPoint, you can lessen the load on the loop by searching for chunks inside the Viewport, instead of individual objects. This would be extremely better than looping the entire game’s instances. You can combine this method with a distance calculation that also uses chunks; when a player is far enough from a chunk, disable shadows for that chunk’s instances. Depending how far you’re willing to go in terms of serialization, the biggest point is to pre-package the game to be unpacked later. Converting and saving your game assets in their most simplest forms, will help lessen the strain of your game loading things. If you have these big elaborate chunks with hundreds of thousands of objects, there’s a couple ways to handle that much data. You can change the size of your chunks, make chunks within chunks, make custom chunks that aren’t square, (loading zones). The possibilities are endless my friend…

2 Likes

Wow, ok, this could work. I not extremely good at scripting. Do you mind starting me off with a rough idea of how the script would go?
Cheers,