Buggy terrain removal with shovel tool

I have made a shovel tool that digs terrain and reveals crates hidden underground. For some reason, only in the live game, mysterious barriers seem to block the player from moving after they remove dirt, and get stuck as a result. I have no idea what’s causing this problem, and it only seems to get stranger the more I test it.

Here’s a video of the problem:

And here’s what I thought would be the be-all-end-all of tests on this which I ran in the dev console:

And the even weirder result that doesn’t seem to make any sense whatsoever:

As you can see the part ended up not directly under me, but a ways away from me as if I had actually fallen into the hole.

I don’t know if this is an engine bug or not, but I have thoroughly looked over my code for the tool, and I haven’t found anything that could cause this behavior. For reference here is the code for the shovel, if you can find the issue it would be greatly appreciated.

in localscript:

local ReplicatedStorage= game:GetService("ReplicatedStorage")
local AudioPlayerModule = require(ReplicatedStorage:WaitForChild("AudioPlayer"))
AudioPlayerModule.preloadAudio({
	["Dig"] = 4925590698
})
 
local rand = Random.new()
script.Parent.Activated:Connect(function()
	if game.Players.LocalPlayer.Character.Head.Position.Y < game.Workspace.Baseplate.Baseplate.Position.Y then
		AudioPlayerModule.playAudio("Dig",1,false)
	end
end)
script.Parent.Deactivated:Connect(function()
	local hum = game.Players.LocalPlayer.Character.Humanoid
	local target = hum.TargetPoint
	local crate = script.Parent.RemoteFunction:InvokeServer(target)
	for i,v in pairs(crate) do
		v.Transparency = 0
		for x,y in pairs(v:GetChildren()) do
			if y:IsA("SurfaceGui") then
				y.Enabled = true
			end
		end
	end
end)

script.Parent.Equipped:Connect(function()
	game.Lighting.GlobalShadows = false
	game.Players.LocalPlayer.CameraMinZoomDistance = 10
end)
script.Parent.Unequipped:Connect(function()
	if game.Players.LocalPlayer.Character.Head.Position.Y > game.Workspace.Baseplate.Baseplate.Position.Y then
		game.Lighting.GlobalShadows = true
		game.Players.LocalPlayer.CameraMinZoomDistance = 0
	end
end)

In regular script:

local flag = false
--remove terrain
function dig(player, part)
	if flag == false then
		flag = true
		if player.Character.Head.Position.Y > workspace.Baseplate.Baseplate.Position.Y then
			game.Workspace.Terrain:FillBlock(CFrame.new(part.Position)*CFrame.new(0,-10,0),part.Size,Enum.Material.Air) -- fixes buggy digging at entrance
		else
			player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
			game.Workspace.Terrain:FillBlock(CFrame.new(part.Position),part.Size,Enum.Material.Air)
		end
		wait(0.095)
		flag = false
	end
end


function script.Parent.RemoteFunction.OnServerInvoke(player,target)
	local part = Instance.new("Part")
	part.Transparency = 1
	part.Anchored = true
	part.CanCollide = false
	part.Position = target
	part.Size = Vector3.new(10,10,10)
	part.Parent = workspace
	local Track = player.Character.Humanoid:LoadAnimation(script.Parent.R15Slash)
	Track:Play(0)
	local digs = coroutine.create(dig)
	coroutine.resume(digs,player,part)
	local crates = {}
	--Make a list of all hidden crates found
	for i,v in pairs(part:GetTouchingParts()) do
		if v:FindFirstChild("giveMoney") then
			table.insert(crates,#crates+1,v)
		end
	end
	part:Destroy()
	return crates
end

By any chance is this on a local script? If so, try and convert it to a serverscript. The terrain isn’t getting deleted serverwise.

The code that does the removal (I’ve used the :FillBlock() method) is in a serverscript, although the function is run through a coroutine and the script itself is inside of the tool when the character uses it. I’m not sure if that changes anything

1 Like

I haven’t read the code but looking at your issues it sounds like it may only be getting deleted on the client and the server isn’t receiving any of the terrain updates.

Yes, I originally thought it was my dummy parts I used to delete the terrain with, but those were always set to cancollide false so it couldn’t be them. It definitely seems like a replication issue now that you and @Messeras mention it, I just don’t know how or why it’s happening

Hm, looking at the script again, I’m not sure if I’m wrong or right but it seems you destroy the part here

which is right before the end.

I’m not a fairly big expert on stuff like this, but wouldn’t you want to refer to the new part created and parented in workspace? It won’t destroy itself if referenced again, as you are just deleting the instanced part, (which isn’t the part you want to destroy)

Also, it may not be a replication issue. Try viewing it from the server when testing.

I see, so I should do something like workspace.Part:Destroy() ? I’ll try it if that’s what you mean.

And I would review it from the server, but this is only happening on the live game. I haven’t been able to encounter the issue in a local test or even a test server with the feature that starts a server in studio.

I think this would work.

workspace:FindFirstChild(part):Destroy()

Unfortunately it still didn’t work

Try doing what I mentioned here as well to diagnose the issue:

I have tried doing this, but strangely I have only come across the issue in the live game, and not in the local studio test mode or even the local server test mode.

Interesting update: The issue does not show up when I run the game on my old PC as opposed to my mac which I’ve done most of the development on.

1 Like

If possible; can I test the game out? I want to see if this happens to me or not.

Yes of course, I’ve set up a test server that guarantees the problem map will be played:

The mine entrance will be on the left side of your base when you spawn in, and you should get the shovel tool automatically

Update: The problem is now happening in studio tests, but the terrain appears to be removed on both the server and the client and there are absolutely no parts getting in the way of the player.

1 Like