Check if the player can see the void and if they can hide it with blocks

Hello, So I have been working on a delete system that when the player deletes a block it will cover the void with other blocks but I have been using raycasting and I just realized that it can be very buggy so I was wondering how would I check if the player can see the void and if the can hide it with blocks.

What I mean is the blocks are 3x3x3 and if the player can see the void then it would hide it with blocks that are snapped to the grid of the generation like what Minecraft does.

~~Here is my server script

DeleteEvent.OnServerEvent:Connect(function(plr, BlockPosition, ClickedVector)
	for i, Part in pairs(BlockGeneratedFolder:GetChildren()) do
		if Part.Position == BlockPosition then
			if Part:IsA("Part") then
				
				local VectorTable = {
					Part.CFrame.LookVector,
					Part.CFrame.LookVector * -1,
					Part.CFrame.RightVector * -1,
					Part.CFrame.RightVector,
					Part.CFrame.UpVector,
					Part.CFrame.UpVector * -1
				}
				
				for i = 1, 6, 1 do
					if i ~= ClickedVector then
						local ray1 = workspace:Raycast(Part.Position + VectorTable[i], VectorTable[i] * 2)
						if not (ray1) then
							BlockModule.CreateFillBlock(Part.Position + VectorTable[i]*3, GenerationObjectFolder, BlockGeneratedFolder)
						end
					end
				end
			end
			
			Part:Destroy()
		end
	end
end)

And this is my local script.

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	if Target ~= nil then
		if (Target.Position - PlayerRoot.Position).Magnitude < MaxDistance then
			--Destroy Target
			BlockOutline.Parent = script
			BlockOutline.Adornee = nil
			
			local SurfaceType = VectorTable[Mouse.TargetSurface.Name]
			if SurfaceType then
				DeleteEvent:FireServer(Target.Position, SurfaceType)
			end
		end
	end
end)

If you would like any more information on what I mean and what I need help with please ask.

Probably Im not able to help you with your goal, but, I just want to make a couple of questions maybe that would return more info about your goal and other Devs could help you.

So, if I destroy a block looking downwards and if my RayCast hits nothing while destroying the block, rebuild the block on the coordinates of the block I destroyed?

But, what about, taggin certain blocks that are the bottom of the map, that when destroyed would be placed again, or directly make those blocks unable to be destroyed?

1 Like