Hello there, I ran into an issue while making a mining system, where the touched event completely ignores the tool.Activated function. I’ve tried many combinations and looked around, however I couldn’t find a definite answer. The script is below. Thanks in advance.
local tool = script.Parent
local canSwing = true
tool.Activated:Connect(function()
if canSwing then
canSwing = false
hitPart.Touched:Connect(function(hit) --This one
if hit.Name == "IronPart" then
print("Iron Mined")
end
end)
wait(1)
canSwing = true
end
end)
Stop creating event connections inside of other event connections.
local tool = script.Parent
local canSwing = true
hitPart.Touched:Connect(function(hit) --This one
if hit.Name == "IronPart" and not canSwing then
print("Iron Mined")
end
end)
tool.Activated:Connect(function()
if canSwing then
canSwing = false
task.wait(1)
canSwing = true
end
end)
Ideally you should have a variabke which tracks whether the tool is activated or not (unless there is some kinda property of Tool which does that)