Mining game producing immense fps drops

I am creating a mining game currently. I have created a mining tool in which the following code samples exist:

Local script:

connection = tool.Activated:Connect(function()
	if active ~= true then
		active = true
		re:FireServer(target)
		target = nil
	end
	connection:Disconnect()
end)

tool.Deactivated:Connect(function()
	if active == true and waiting == false then
		waiting = true
		connection:Disconnect()
		task.wait()
		active = false
		waiting = false
	end
end)

(Where target is defined by the mouse target block, active and waiting are defined as “false” earlier in the script, and re is a remote event)

Global script:

local sp = script.Parent
local re = script.remoteevent


local function activate(plr, target)
	if target then
		target:Destroy()
	end
	target = nil
	plr = nil
end

re.OnServerEvent:Connect(activate)

The problem I am facing is that the more blocks I mine, the more terrible my fps seems to get. I do run a low end pc but this never happens in other mining games I’ve played. I go from a solid 60 fps to less than 15 if I mine for long enough. I’ve tried fixing this by adding connections & disconnecting them, adding wait times, defining target & plr as nil at the end of the global script, making sure the target actually still exists when it gets to the global script and probably a couple other things I forgot about. Not sure what to do!

3 Likes

How do you know that it is the tool causing this?

1 Like

I don’t see why it wouldn’t be. As mentioned, I’ve never had this issue with other mining games so I’m sure it’s not a rendering thing, especially considering I have barely any parts in the game as it stands now. Also, the more blocks you break the larger the fps drop is. As soon as you stop mining your fps shoots right back up to where it should be. Since you are getting rid of material (as blocks already exist to destroy) I do not see why removing material would cause anything like this. Hence, I believe there is something going on in the script that I’m not seeing that is causing this effect.

If you say were destroying blocks using studio’s “Run” feature you would not expect your fps to drop (assuming you are removing material 1 by 1) which hopefully gets what I am trying to say across?

Create a new baseplate and paste in only the things you want to test.

The blocks and the tool.

See if the problem persists.

1 Like


Unfortunately, that is practically what I’m working with!