Hi, im currently using a script that clones parts into a viewport that only region3 detects, however Im trying to make it so it will delete the parts it cannot see.
Code:
--Ignore list/Whitelist for the region3
local ViewportHandler = require(script.ViewportHandler)
local staticDelay = 60 -- the amount of time it takes to update static parts, in steps
local VF_Handler = ViewportHandler.new(script.Parent.ViewportFrame)
local renderDistance = 100
local list = {workspace.ViewportPart, workspace.CamPart, humanoidcurrent}
local PartLimit = 100
local camera = Instance.new("Camera", script.Parent) -- Create the camera
camera.CFrame = script.Parent.Adornee.CFrame + script.Parent.Adornee.CFrame.LookVector*2
local viewport = script.Parent.ViewportFrame
viewport.CurrentCamera = camera
local function renderStatic()
--Create the region3 to detect the parts
local center = (camera.CFrame.LookVector*renderDistance)/2
local corner = Vector3.new(renderDistance/2,renderDistance/4,renderDistance/2)
local renderRegion = Region3.new(center - corner, center + corner)
--Get all parts within the region
local parts = workspace:FindPartsInRegion3WithIgnoreList(renderRegion, list, PartLimit)
--Loop through the parts
for i,v in pairs(parts) do
if v.ClassName == "Part" or v.ClassName == "MeshPart" or v.ClassName == "BasePart" or v.ClassName == "SpawnLocation" or v.ClassName == "CornerWedgePart" or v.ClassName == "WedgePart" or v.ClassName == "Decal" or v.ClassName == "SpecialMesh" then
if not v.Parent:FindFirstChild("Humanoid") then
if not v.Parent.Parent:FindFirstChild("Humanoid") then
if not v:FindFirstChild("Render1") then
render1 = Instance.new("BoolValue")
render1.Name = "Render1"
render1.Parent = v
partcurrent = VF_Handler:RenderObject(v,workspace.Commands.FPS.Value)
end
end
end
end
if v.ClassName == "Model" then
if v:FindFirstChild("Humanoid") then
if v ~= game.Players.LocalPlayer.Character then
if not v:FindFirstChild("Render2") then
render2 = Instance.new("BoolValue")
render2.Name = "Render2"
render2.Parent = v
humanoidcurrent = VF_Handler:RenderHumanoid(v,workspace.Commands.FPS.Value)
end
end
end
end
if not v then -- doesn't detect
if partcurrent == v then
render1:Destroy()
partcurrent:Destroy()
end
if humanoidcurrent == v then
render2:Destroy()
humanoidcurrent:Destroy()
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(function()
renderStatic()
end)