For some odd reason, my pickaxe just isn't hitting apparently

Currently, I have been making a pickaxe/mining script, but the Touched script in generally just isn’t working at all.

Although, I can quite obviously see that the can touch function exists, and seemingly works.

So, even before I start getting errors with my attributes, it seems as if the touched event just isn’t working.

First of all, “Hit” returns the instance that was hit, not the name. “Print()” only works with strings, and you’re trying to print the instance of the hit value. To avoid this, use “print(Hit.Name.)”

Also, is the “Ores” thing a model or a part? If it’s a model, then use print(Hit.Parent.Name). Otherwise, use print(Hit.Name).

The reason why you weren’t starting to get errors with your attributes is because the script automatically stops itself at the print(hit) because of the error.

The issue still holds. For some reason the Touched function will not print out the name, and it’s not even showing up as nil. Ores is a Tag, apart of Collection Service, to specifically check only for that certain group of things, in this case being Ores. The script doesn’t seem to go past that first print for some reason and I simply just fail to understand why, even after adding the .Name part of the script.

-- \\ Get-Services Variables // --

local RS = game:GetService("ReplicatedStorage")

local CS = game:GetService("CollectionService")

local SP = game:GetService("StarterPack")

-- \\ RS Variables // --

local Mine = RS.ProgressionRelated.Mining

-- \\ Tools // --

local PA = SP.Pickaxe.Handle.Union



-- \\ Functions // -- 


Mine.OnServerEvent:Connect(function()
	PA.Touched:Connect(function(Hit, Health)
		print(Hit.Name)
		if CS:HasTag(Hit, "Ores") then
			print("Ores")
			local HP = Hit.Parent:GetAttribute("HP").Value
			print("StillWorking")
			Health = HP
			print("Possibly still working")
			Hit.Parent:SetAttribute("HP", Health-1)
			print("Might be broken here")
			print(HP)
			if HP <= 0 then
				print("RockBroken")
			end
		end
		
	end)
end)

Did you try going to View > Output for checking errors instead of just using the developer console for checking printing?

Yeah, and yet still nothing prints.

Can you try printing on line 22 to see if/when the Mine.OnServerEvent is triggering.

Yeah, I did. It seems to be printing after the event.

It must be a problem with the “if CS:HasTag(Hit, “Ores”) then” block. You should add an “else” and then print something to see if it’s returning as false.

image

if CS:HasTag(Hit, "Ores") then 
			print("Ores")
			local HP = Hit.Parent:GetAttribute("HP").Value
			print("StillWorking")
			Health = HP
			print("Possibly still working")
			Hit.Parent:SetAttribute("HP", Health-1)
			print("Might be broken here")
			print(HP)
			if HP <= 0 then
				print("RockBroken")
			else
				print("No tag, LOL")
			end
		end

No print. It’s very odd.

You placed it wrong. Put the else somewhere else.

if CS:HasTag(Hit, "Ores") then 
	print("Ores")
	local HP = Hit.Parent:GetAttribute("HP").Value
	print("StillWorking")
	Health = HP
	print("Possibly still working")
	Hit.Parent:SetAttribute("HP", Health-1)
	print("Might be broken here")
	print(HP)
	if HP <= 0 then
		print("RockBroken")
	end
else
	print("No tag, LOL")
end



Still no changes for some reason.

So the event prints, the touch prints, but everything after does not print? Weird…

That’s what I have been saying. I would put this in bugs, but I want to see if it is a bug, or it’s just me being an incompetent scripter.

For some reason, once I do it on the client, the script seems to work? I’m going to attempt to move the script to the actual tool. The whole thing does work, once I place it within a local script. So, what does that mean?

I just read an article and it said to use a LocalScript to listen for the tag. I didn’t read the whole thing though, I just typed in “LocalScript” in Cmd + F and that was the thing that popped up.

So try checking for the tag in a local script and use an event to fire everything else.

I managed to fix it though seeing another script, and trying another solution. It wasn’t seeing the things in SP, so I had to fix it a little.

So is everything working as intended now?

1 Like

I don’t know what your Pickaxe’s LocalScript looks like, but you ideally want to be detecting touches on the client for this, while also detecting user input. When both debounces align, you can fire a remote to let the server know it’s okay to damage the ore. You’d need sanity checks with this of course.

Logpoints would make debugging this easier so you don’t need to add a print everywhere, just a tip.

Few things I see that could be the culprit -

  • Touched is created whenever Mine remote is fired; this will cause a memory leak when fired multiple times and you might not be receiving a response from the client to initiate the Touched event.
  • Touched passes the part that made contact with the part as its only argument. Health is unlikely to ever exist. Make sure to not pass this through the client/server boundary.
  • You can’t get .Value out of an attribute. Attributes do not support Instances either. I assume you’re trying to do this on a number.

Yeah, the attribute issue is now the problem. It would’ve been nice to do so, but I guess not. What is the alternative method I can do?

You can always use a NumberValue for your “HP”.