How to destroy a certain terrain with a tool?

  1. What do you want to achieve?
    I want to make a tool that can dig through rock terrain.

  2. What is the issue?
    I don’t know where to start.

  3. What solutions have you tried so far?
    I’ve looked through free models that can destroy terrain but it confused me.

Basically I just want some help making a tool that can destroy rock when I click with the tool. I have no experience with tool but I want it to happen when the tool is activated?

Thanks, if you can help.

You can create a sphere region basing on mouse hit or using ScreenPointToRay to raycast :slight_smile: , pretty tiny, then use workspace.Terrain and use :ReplaceMaterial() with material Enum.Material.Air

You could try and look at this:

And have that destroy function play once the tool is activated like this:

function onClick()
       -- Destroy function here.
end
script.Parent.Activated:Connect(Onclick)

Put that script inside of the tool you want, if you don’t know how to create a tool here is another official tutorial (you can find a lot of useful things on the Roblox Wiki):

1 Like

I’ve never used any of those, I’ll read about them on the devhub.

I’ll take a look at them, thanks.

1 Like

No problem, good luck on future scripting!

1 Like

Hello again!

function onClick()
	local mouse = game.Players.LocalPlayer:GetMouse()
	local recordedPosition = game.Workspace.Terrain:WorldToCellPreferSolid(mouse.Hit.p)
	game.Workspace.Terrain:SetCell(recordedPosition.X,recordedPosition.Y,recordedPosition.Z,0,0,0)
end

script.Parent.Activated:Connect(onClick)

I’ve got that, it works perfectly! However, it’s local. Is there a good way to do it on the server? I tried doing this:

  • client:
function onClick()
	local mouse = game.Players.LocalPlayer:GetMouse()
	local recordedPosition = game.Workspace.Terrain:WorldToCellPreferSolid(mouse.Hit.p)
	game.ReplicatedStorage.Server.RF.Terrain:InvokeServer(recordedPosition)
end

script.Parent.Activated:Connect(onClick)
  • server:
game.ReplicatedStorage.Server.RF.Terrain.OnServerInvoke = function(plr,pos)
	game.Workspace.Terrain:SetCell(pos.X,pos.Y,pos.Z,0,0,0)
end

however it did not work, is there any other way?

I see you used a remote function but you could also do a remote event here is some information:

As for that not working, was there any errors maybe make the tool fire the event that just prints “activated” to make sure the client script works.

Changing it over to a remote event worked! Thank you, again.

hands over another solution

2 Likes

No problem I’m so happy to help!

1 Like