.LocalScript:4: attempt to index nil with 'Target'

I’m trying to create a pickaxe system for mining ores, I keep getting this error though. The hierarchy is shown below but if you need any more info I can send it, thanks for your help. This is a local script in a tool.


image

1 Like

Activated does not return any parameters that’s why its nil. what do you want hit to be?

The Activated event does not return a hit parameter (as previously said), so you would have to implement this yourself. You are also using GetChildren incorrectly and not properly checking for specific objects. The GetChildren method returns an array of children objects. Using it within the IsA method wouldn’t make sense because it expects a class name as a string, not an array.

In regards to how to improve your function, I would suggest either looping through the spawn nodes to check if the target is one of them, or use CollectionService and tag the objects so that you could have a check like Hit.Target:HasTag("SpawnNode") instead.

1 Like

How would I register if the stone had been clicked by the mouse while holding the tool?

local Equipped = false
local pickaxe = script.Parent
spawnNodes = game.Workspace.spawnNodes:GetChildren()

pickaxe.Equipped:Connect(function()
	Equipped = true
end)

pickaxe.Unequipped:Connect(function()
	Equipped = false
end)

for __,x in ipairs(spawnNodes) do 
	print(x)
	
end```

youd need to use a remote function to get the mouse position when the tool is activated

1 Like