How can I keep terrain editing from exposing underground

I’ve built a simple dig tool that players can use to find boxes that are hidden underground in smooth terrain. The issue originally was that it was too dark underground, so I made the activation of the tool turn off global shadows for the player. That fixed the darkness issue, but it gave the digging another problem. It seems for some clicks that the terrain lags slightly when trying to fill with air and you can temporarily see all the boxes underground with x-ray vision! I tried putting a pointlight on the player’s head instead of turning off the shadows but you can still see them pretty clearly. Is there a better way to be editing the terrain? The problem seems to persist even when using ReplaceMaterial instead of FillBlock

LocalScript

script.Parent.Deactivated:connect(function()
	local hum = game.Players.LocalPlayer.Character.Humanoid
	local target = hum.TargetPoint
	script.Parent.RemoteEvent:FireServer(target)
end)

--make underground visible
script.Parent.Equipped:Connect(function()
	game.Lighting.GlobalShadows = false
end)
script.Parent.Unequipped:Connect(function()
	if game.Players.LocalPlayer.Character.Head.Position.Y > game.Workspace.Baseplate.Baseplate.Position.Y then
		game.Lighting.GlobalShadows = true
	end
end)

Script:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player,target)
	if player.Character.Head.Position.Y > workspace.Baseplate.Baseplate.Position.Y then
		game.Workspace.Terrain:FillBlock(CFrame.new(target)*CFrame.new(0,-10,0),Vector3.new(10,10,10),Enum.Material.Air) -- fixes buggy digging at entrance
	else
		game.Workspace.Terrain:FillBlock(CFrame.new(target),Vector3.new(10,10,10),Enum.Material.Air)
	end
end)

A really neat idea would be to either generate the boxes when the player breaks a certain terrain block,
or to make them visible when they are truly visible.

Other than that, that’s just the engine being faulty when it updates

1 Like

Perhaps when the box detects a change in the voxels around it, it would make itself visible? My only worry would be that continuously reading the voxels on a loop might be resource intensive, I don’t really know that much about how much roblox servers can handle.

You could use RemoteFunctions and a server script.

Fire the remote function within the tool to destroy a terrain part,
then have the server check for box positions around the terrain part position

Just made it so that it makes a part around the target and checks all the parts touching it. If there’s a box it’s made visible to the client. Thank you so much, it works like a charm

1 Like