Problem with mining system

local pickaxe = script.Parent
local canmine = pickaxe.CanMine
local anim = pickaxe.Animation
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local animtrack
local humanoid

player.CharacterAdded:Connect(function(character)
	humanoid = character:WaitForChild("Humanoid")
	animtrack = humanoid:LoadAnimation(anim)
end)
	
canmine.Value = true

pickaxe.Activated:Connect(function()
	if canmine.Value == true then
		print("activated")
		animtrack:Play()
		canmine.Value = false
		pickaxe.Touched:Connect(function(hit)
			if hit.Name == "Rock" or hit.Parent == "Rocks" then
				print("mining")
			end
		end)
		task.wait(1)
		canmine.Value = true
	end
end)

I have a script for a mining system in my game. If the pickaxe touched the rock then it will print “mining” in the output, but it returns an error saying “Touched is not a valid member of Tool “Workspace.player_name.Pickaxe””. Im new at scripting so, i don’t really know how to fix this. Can anyone help?

every time you activate the pickaxe it will create a new .Touched Connection. The print + error message you describe doesn’t make too much sens to me, but this may be the issue. If it isn’t I believe you mean to use the tool’s .Handle

Try creating a Touched connection outside of the Activation function like so


pickaxe.Activated:Connect(function()
	if canmine.Value == true then
		print("activated")
		animtrack:Play()
		canmine.Value = false

		task.wait(1)
		canmine.Value = true
	end
end)

pickaxe.Handle.Touched:Connect(function(hit)
	if canmine == false and hit.Name == "Rock" or hit.Parent == "Rocks" then
		print("mining")
	end
end)

The pickaxe needs to be a part not a model as in the touching part. Models can’t sense when it’s bein touched.

i tried it too but it doesn’t seem to work for me but still thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.