So I am trying to make a really simple mining system, a few issues

So the biggest issue at the moment, is that if theres 2+ rocks inside the game, one cant be mined and the other can be mined, but when you mine the mineable rock, it destroys the unmineable rock.
image

Shown by my beautiful art and diagram on the top grade emulator.
Im curious on how I could fix this, as I am a little confused.

(by the way the ‘mining’ system is more of a simple click the rock with a pickaxe equipped enough times to clear the route)

Tool Local Script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local pickaxe = script.Parent

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local Equip = humanoid:LoadAnimation(script.Parent.Equip)
local Idle = humanoid:LoadAnimation(script.Parent.Idle)
local Strike = humanoid:LoadAnimation(script.Parent.Strike)

local debounce = false

pickaxe.Equipped:Connect(function()
	Equip:Play()
	wait(1.32)
	Equip:Stop()
	Idle:Play()
end)

pickaxe.Unequipped:Connect(function()
	Equip:Stop()
	Idle:Stop()
end)

pickaxe.Activated:Connect(function()
	wait(.5)
	
	local dist = (character.HumanoidRootPart.Position - mouse.Target.Position).Magnitude 

	if mouse.Target == game.Workspace.rock and dist < 6 and debounce == false then
		debounce = true
		Strike:Play()
		Idle:Stop()
		print("hit rock")
		local pickaxeSFX = Instance.new("Sound")
		pickaxeSFX.SoundId = "rbxassetid://dontlookatthis:)"
		pickaxeSFX.Volume = 2.2
		pickaxeSFX.Parent = character.HumanoidRootPart
		game.ReplicatedStorage.PickaxeDamage:FireServer()
		wait(1.5)
		debounce = false
		pickaxeSFX:Destroy()
		Idle:Play()
	else
		print("Out of Range / No rock detected")
	end
end)

Server Local Script (Inside the rocks that are in the diagram)

local rockHP = 5

game.ReplicatedStorage.PickaxeDamage.OnServerEvent:Connect(function()
	rockHP -= 1
	if rockHP <= 0 then
		script.Parent:Destroy()
	end
end)

Do you only want the rock to be mined for one person and not the entire server?

no the rock should be destroyed on the server

Make the script in the rocks a normal script, and hold on while i think of a solution

whar? you mean a server script inside the rock? because thats already the case.

It seems that all the rocks are connected to the same remote and is effectively damaging all the rocks in the game after calling the remote since they are all connected to OnServerEvent without any kind of checks if it’s them that’s meant to be hit.

1 Like

You could just have a server script inside of the rock that, when clicked, checks if the tool is a child of the character, and if it is, mine the block

you can use magnitude to ensure it can’t be mined from infinite distances

I figured that was the case, Is there any tweaks I should do? or should i try to experiment with @ryuukoori 's solutions

I’ll see if I can make something similar myself; hold on

What I would do is to make only one script handling all the rocks and make the client send the rock they want to hit as an argument, also you should probably make your distance checks on the server so exploiters can’t hit rocks.