I am creating a mining game and have spent the past few days making assets, the assets I have are, a shovel and an excavator with working joints but I can’t connect the touched function the the bucket for the life of me, The terrain filling script someone gave me a hand with and wont respond to me so I can’t understand how to get the bucket’s position instead of the mouse.
function dig(player,blob)
workspace.Terrain:FillBlock(CFrame.new(blob),Vector3.new(5,5,5),--[[mouse.Target.Material]]Enum.Material.Air)
end
game.ReplicatedStorage.Dig.OnServerEvent:Connect(dig)
And as the comment says mouse.Target.Material so I tried calling the bucket mouse and that didn’t work, the touched event is fairly simple, its just the connecting i’m struggling with, here is the function i’m using in a script in the bucket
Where I Am At Trying;
local terrain = game.Workspace.Terrain
terrain.Touched:Connect(function(dig)
if dig.Name == "Bucket" then
workspace.Terrain:FillBlock(CFrame.new(blob),Vector3.new(5,5,5),--[[mouse.Target.Material]]Enum.Material.Air)
end
end)
Normally scripting can be a whizz with functions for me but this time I got nothing
on line 4 it is something to do with the blob, I just extracted the line from the shovel I have, it uses a local script and a script
the local script;
script.Parent.Equipped:connect(function(mouse)
script.Parent.Activated:connect(function()
local char = script.Parent.Parent
if script.Parent.Value.Value == false then
game.ReplicatedStorage.Dig:FireServer(mouse.hit.p)
end
if script.Parent.Value.Value == true then
game.ReplicatedStorage.Place:FireServer(mouse.hit.p)
end
--workspace.Terrain:FillBlock(mouse.hit,Vector3.new(7,10,7),--[[mouse.Target.Material]]Enum.Material.Air)
end)
end)
and the script;
local value = script.Parent.Value
function dig(player,blob)
if value.Value == false then
workspace.Terrain:FillBlock(CFrame.new(blob),Vector3.new(5,5,5),--[[mouse.Target.Material]]Enum.Material.Air)
value.Value = true
end
end
game.ReplicatedStorage.Dig.OnServerEvent:Connect(dig)
local value = script.Parent.Value
function fill(player,blob)
if value.Value == true then
workspace.Terrain:FillBlock(CFrame.new(blob),Vector3.new(2,2,2),--[[mouse.Target.Material]]Enum.Material.Ground)
value.Value = false
end
end
game.ReplicatedStorage.Place.OnServerEvent:Connect(fill)
I should probably have put these in the post but these do not create errors and I can’t see and explicit local blob = blank
You should just pass mouse.hit instead of mouse.hit.p because mouse.hit is already a cframe value, so you can just write blob instead of CFrame.new(blob)
its not the shovel, the shovel works perfectly fine now but its the excavator. What I am trying to do is make it so when the bucket collides with the ground the terrain beneath it is destroyed but I cant get the terrain to destroy because I believe the script is wrong as it returns
12:06:59.272 - Argument 1 missing or nil
on line 4 of the script
local terrain = game.Workspace.Terrain
terrain.Touched:Connect(function(dig, blob)
if dig.Name == "Bucket" then
workspace.Terrain:FillBlock(blob,Vector3.new(5,5,5),--[[mouse.Target.Material]]Enum.Material.Air)
end
end)
but that line was made for a shovel and where a player clicks, not where a part is which is where I am stumped
So I added a variable to the bucket and it gives no errors but it still doesn’t destroy the terrain, could it be that it needs to do the math of below the bucket instead of its location?
by that I mean I created a variable above the script to reference the bucket