Hey! so currently im working on a limited rendering viewport system. However for some reason I keep getting this "attempt to index nil with “FindFirstChildOfClass” error even though the part is clearly there.
local ViewportHandler = require(script.Parent.ViewportHandler)
local Frame = script.Parent.ViewportFrame
local RunService = game:GetService("RunService")
local VF_Handler = ViewportHandler.new(Frame)
local BoxCFrame = workspace.CameraViewportPart.CFrame * CFrame.new(Vector3.new(0, 0, -38.5))
local BoxSize = Vector3.new(75,75,75)
local Params = OverlapParams.new() -- Defaulted to blacklist,
Params.FilterDescendantsInstances = { workspace.CameraViewportPart }
local lastParts = {}
while true do
BoxCFrame = workspace.CameraViewportPart.CFrame * CFrame.new(Vector3.new(0, 0, -38.5))
local parts = workspace:GetPartBoundsInBox(BoxCFrame,BoxSize,Params)
local partsAdded, partsRemoved = {}, {}
for i, part in ipairs(parts) do
if not table.find(lastParts, part) then
table.insert(partsAdded, part) -- this part was added
if not part.Parent:FindFirstChildOfClass("Humanoid") then
if not part.Parent.Parent:FindFirstChildOfClass("Humanoid") then
if not part:FindFirstChild("RenderObjectValue") then
renderpart = VF_Handler:RenderObject(part,workspace.Commands.FPS.Value)
end
end
end
if part.Parent:FindFirstChildOfClass("Humanoid") then
if not part.Parent:FindFirstChild("RenderObjectValue") then
renderhumanoid = VF_Handler:RenderHumanoid(part.Parent,workspace.Commands.FPS.Value)
end
end
end
end
for i, part in ipairs(lastParts) do
if not table.find(parts, part) then
table.insert(partsRemoved, part) -- this part was removed
if part:FindFirstChild("RenderObjectValue") then
if part.RenderObjectValue.Value ~= nil then
part.RenderObjectValue.Value:Destroy()
part.RenderObjectValue:Destroy()
end
end
if part.Parent:FindFirstChildOfClass("Humanoid") then
if part.Parent:FindFirstChild("RenderObjectValue") then
part.Parent.RenderObjectValue.Value:Destroy()
part.Parent.RenderObjectValue:Destroy()
end
end
end
end
lastParts = parts -- save the parts from the current iteration to be contrasted with parts from the next iteration
-- now, partsAdded will be a table of parts that are new
-- partsRemoved will be a table of parts that have been removed since the last iteration
wait(0.5)
end
basically render humanoid and render part just clones the part into the viewport as well as making an object value, which the object values value is the clone in the viewport in the module. btw, I know im using alot of if statements, I just find it more better.