I want to only render blocks inside (or touching) a part, but when I test it it won’t show any blocks (except for the blacklisted parts).
I don’t know why, but :GetPartsInPart always returns 0, and I don’t know where’s the problem. (I’m not that good at scripting)
Local Script:
local repStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")
local currentcam = game.Workspace.CurrentCamera
local road = game.Workspace.CutsceneSets.RealWorldSet.Outdoors.Road:GetDescendants()
local temp1 = game.Workspace.CutsceneSets.RealWorldSet.Outdoors.Temp1:GetDescendants()
local temp2 = game.Workspace.CutsceneSets.RealWorldSet.Outdoors.Temp2:GetDescendants()
local blacklist = {}
local debounce = false
local towcam = false
local camview = false
local founditems = 0
for i, v in ipairs(road) do
if v:IsA("Part") then
table.insert(blacklist, v)
end
end
for i, v in ipairs(temp1) do
if v:IsA("Part") then
table.insert(blacklist, v)
end
end
for i, v in ipairs(temp2) do
if v:IsA("Part") then
table.insert(blacklist, v)
end
end
local workspacedescendants = game.Workspace:GetDescendants()
local whitelist = {}
for i, v in ipairs(workspacedescendants) do
if v:IsA("Part") then
local bruh = true
for j = 1, #blacklist do
if blacklist[j] == v then
bruh = false
end
end
if bruh == true then
table.insert(whitelist, v)
end
bruh = true
end
end
repStorage.RegisterCamToPlayer.OnClientEvent:Connect(function(plrCam)
local view = plrCam:FindFirstChild("CamView") --welded to tocam
local tocam = plrCam:FindFirstChild("ToCam") --always moves to cam's CFrame, has weld constraint welded to view. I already checked if it's moving, and it is.
for i, v in ipairs(blacklist) do
if v == view then
camview = true
elseif v == tocam then
towcam = true
end
end
if camview == false then
table.insert(blacklist, view)
end
if towcam == false then
table.insert(blacklist, tocam)
end
runService.Heartbeat:Connect(function()
if debounce == false then
debounce = true
for i, v in ipairs(whitelist) do
v.CanCollide = false
v.Transparency = 1
end
tocam.CFrame = currentcam.CFrame
local itemsfound = game.Workspace:GetPartsInPart(view, OverlapParams.new(whitelist, Enum.RaycastFilterType.Whitelist))
for i, v in ipairs(itemsfound) do
founditems += 1
v.CanCollide = true
v.Transparency = 0
end
print(founditems)
task.wait()
debounce = false
founditems = 0
end
end)
end)
Script:
local plrService = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local cam = repStorage:WaitForChild("Cam")
plrService.PlayerAdded:Connect(function(plr)
local CamClone = cam:Clone()
CamClone.Parent = game.Workspace
repStorage.RegisterCamToPlayer:FireClient(plr, CamClone)
end)
Thank you for your help : )