What do you want to achieve?
I want to make a tool that can dig through rock terrain.
What is the issue?
I don’t know where to start.
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?
You can create a sphere region basing on mouse hit or using ScreenPointToRay to raycast , pretty tiny, then use workspace.Terrain and use :ReplaceMaterial() with material Enum.Material.Air
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):
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