Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Making parts not render after a certain distance?

Hello so I was wondering how this would be possible, I was browing through roblox when I saw this patch on a game and surprisingly it did fix the lag by a whole lot.

  • Power Abilities won't render at far distances (Lag Fixed) ~ Source: Ro - Piece

I was in search of something like this already but never quite knew how to do it, is there any way to change the rendering distance of certain parts and effects?

1 comment

0

Couldn't you use StreamingEnabled

1 answer

as incapaxx said, you could use StreamingEnabled but if not, you could use these functions

-- used to check distance from character

local maxDistance = 20

function checkDistanceFromChar(character,part)
	local plr = game.Players:GetPlayerFromCharacter(character) -- gets player
	if plr:DistanceFromCharacter(part.Position) > maxDistance then
		-- put code here
	end
end

-- this works by checking the distance from the character to the part

However, if you want to use CurrentCamera (assuming your using a LocalScript) then you could use something like this:


local maxDistance = 20

function checkDistanceFromCam(part)
	local cam = workspace.CurrentCamera -- gets camera
	if (cam.CFrame.Position-part.CFrame.Position).Magnitude > maxDistance then
		-- put code here
	end
end

-- this works by checking the magnitude of the camera's position minus the part's position

1 comment

0

magnitude is basic stuff, that's not what I needed, I wanted to find a way to make them not render, I guess I am going to follow incapaz's advice

This discussion is preserved as it was. New answers, comments, and votes are closed.