I want to make a Spade/Shovel that lets you dig away a bit of terrain at the mouse position when the left button is clicked.
I tried using Terrain:FillRegion and to fill it with air material but it doesnt work, I already checked if the distance if statement was the problem, but it isnt!
This is what my script looks like:
local RE = script.Parent:WaitForChild("RemoteEvent")
local tool = script.Parent
local dmg = 60
local RaycastModule = require(tool:WaitForChild("RaycastHitboxV4"))
--- Create the hitbox for our tool
local Hitbox = RaycastModule.new(tool:WaitForChild("Metal"))
local BayRaycastParams = RaycastParams.new()
BayRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
--- Set our Hitbox's RaycastParams to the one we just created
Hitbox.RaycastParams = BayRaycastParams
Hitbox.Visualizer = false
function hitdetect()
Hitbox:HitStart() --- Starts the hit detection
task.wait(0.25) --- Wait a few seconds
Hitbox:HitStop() --- Stops the hit detection
end
Hitbox.OnHit:Connect(function(hit, humanoid)
if hit.Name == "Head" then
humanoid:TakeDamage(dmg * 1.5)
else
humanoid:TakeDamage(dmg)
end
tool:WaitForChild("Handle"):WaitForChild("HitPlayer"):Play()
end)
RE.OnServerEvent:Connect(function(plr, instruction, sound, mousePos)
if instruction == "Swing" then
sound:Play()
task.spawn(hitdetect)
elseif instruction == "Equip" then
BayRaycastParams.FilterDescendantsInstances = {plr.Character}
sound:Play()
elseif instruction == "Unequip" then
BayRaycastParams.FilterDescendantsInstances = {}
elseif instruction == "Dig" then
local character = plr.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local characterPosition = humanoidRootPart.Position
local mousePosition = mousePos
local distance = (characterPosition - mousePosition).Magnitude
if distance <= 5 then
local terrain = game:GetService("Workspace"):WaitForChild("Terrain")
local regionToDig = Region3.new(mousePosition - Vector3.new(2,2,2), mousePosition + Vector3.new(2,2,2))
terrain:FillRegion(regionToDig, 50, Enum.Material.Air)
end
end
end
end
end)
–pls help me im in a basement in asia working to make games for a greedy man
–just kidding