I have made a system that should dig a hole where the player clicks but the scale seems to be off or something.
robloxapp-20210411-0951248.wmv (3.7 MB)
Here is my code
Local script:
local uis = game:GetService("UserInputService")
local mosue = game.Players.LocalPlayer:GetMouse()
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local params = RaycastParams.new()
params.FilterDescendantsInstances = {game.Workspace.Terrain}
params.FilterType = Enum.RaycastFilterType.Whitelist
uis.InputBegan:Connect(function(input,gp)
if not gp then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouseHitDirection = mosue.Hit.lookVector
local hit = game.Workspace:Raycast(game.Workspace.CurrentCamera.CFrame.Position,mouseHitDirection*50,params)
if hit then
game.ReplicatedStorage.Dig:FireServer(hit.Position)
end
end
end
end)
Server Script:
game.ReplicatedStorage.Dig.OnServerEvent:Connect(function(plr,hit)
local part = Instance.new("Part")
part.Anchored = true
part.Position = hit
part.Parent = game.Workspace
part.Transparency = 0.5
part.CanCollide = false
terrainChange(hit-(digsize/2),hit+(digsize/2),Enum.Material.Air,true)
end)
Terrain Change function, the “actualdata” are just the X, Y, and Z from the first two arguments in terrainChange()
local region = Region3.new(Vector3.new(actualdata[1],actualdata[2],actualdata[3]),Vector3.new(actualdata[4],actualdata[5],actualdata[6]))
game.Workspace.Terrain:FillRegion(region ,1,Enum.Material.Air)