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)
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.
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
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
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 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.