Help with terrain mining?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Basically. I want to create a system that can mine away on terrain.Pretty simple [:

  1. What is the issue? Include screenshots / videos if possible!

Im not sure if im doing this wrong(Probs am). But why isnt my code changing the cell position to air? im using “WorldToCellPreferSolid()” to get the cell location as you will see from my code in a sec.

What exactly am i doing wrong. Shouldnt “FillBall()” set the cell position to air? or am i missunderstanding it completley?

SetCell() works to clear out terrain. But since thats deprecated its not very reliable.

Heres my code. Also before someone mentions it. I know GetMouse() is deprecated. Im only using it for testing purposes!!

local P = game.Players.LocalPlayer
local M = P:GetMouse()






M.Button1Down:Connect(function()
	local Pos = workspace.Terrain:WorldToCellPreferSolid(M.Hit.Position)
	
	workspace.Terrain:FillBall(
		Pos,
		5,
		Enum.Material.Air
	)
end)

Based on the information you provided, it seems that the issue you are facing is that the cells in the terrain are not being changed to air when you use the FillBall() function. You are using the WorldToCellPreferSolid() function to get the cell location from the mouse position, but it is not working as expected.

What you want to achieve is to create a system that can mine away terrain using code.

To solve the issue, you can try the following:

  1. Check if the Pos variable is being set correctly by printing it to the output using print(Pos) after local Pos = workspace.Terrain:WorldToCellPreferSolid(M.Hit.Position) .
  2. Make sure that the FillBall() function is being called with the correct arguments. The first argument is the center of the ball, the second argument is the radius, and the third argument is the material to fill the ball with. In your case, it should be Enum.Material.Air .
  3. Try using the SetCell() function instead of FillBall() . The SetCell() function is not deprecated and can be used to set the material of a single cell.

Here is an example of how you can use the SetCell() function:

M.Button1Down:Connect(function()
    local Pos = workspace.Terrain:WorldToCellPreferSolid(M.Hit.Position)
    workspace.Terrain:SetCell(Pos.X, Pos.Y, Pos.Z, Enum.Material.Air)
end)

This code will set the material of the cell at Pos to air.

I hope this helps you solve the issue. Let me know if you have any further questions.

1 Like

Alright thanks that works. But id rather not use setcell() if it isnt necessary since it does mention on the docs its deprecated.
image

Here is an example of how you can use the FillRegion() function:

M.Button1Down:Connect(function()
    local Pos = workspace.Terrain:WorldToCellPreferSolid(M.Hit.Position)
    local radius = 5
    local size = Vector3.new(radius, radius, radius)
    local region = Region3.new(Pos - size, Pos + size)
    workspace.Terrain:FillRegion(region, Enum.Material.Air)
end)

This code will create a region centered at Pos with a radius of 5 , and then fill it with air.

1 Like

What should the resolution value be?
image

Resolution always has to be set to 4.

1 Like

Alright thanks. That does kinda work only problem left is that the region seems to always be at the center of the world?

Nvm solved it. Turns out it was this easy. Thanks to everyone who helped though :smiley:

local M = game.Players.LocalPlayer:GetMouse()




M.Button1Down:Connect(function()
	workspace.Terrain:FillBall(M.Hit.Position,5,Enum.Material.Air)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.