Variable Tool:Activate() Problem

Hi There, i was Scripting a Tool Activates whatever they Touch HumanoidRootPart.

and i give 3 Tools to the NPC’s Inventory and i started to script to Touch HumanoidRootPart that Tool Activate. and i tested out the script and when NPC’s Tool Touches HumanoidRootPart with Sword, and nothing happens. and i have no clue to fix it.

Here’s a Script:

local Tool = script.Parent:FindFirstChildOfClass("Tool")
Tool.Handle.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" then
		local Tool_deboune = false
		if Tool_deboune == false then
			Tool:Activate()
			Tool_deboune = true
			delay(1, function()
				Tool_deboune = false
			end)
		end
	end
end)

it Has 3 Tools in NPC’s Inventory for Example:

  1. ClassicSword
  2. Dark of Sword
  3. Healing Potion

Please Give me a any solutions to fix it issues

Could you show the layout in the explorer

It looks like one of the issues with your script is that the Tool_deboune variable is being set to false inside the function, making the debounce check ineffective. To fix this, move the Tool_deboune variable outside the function so it maintains its state between function calls. Here’s the corrected script:

local Tool = script.Parent:FindFirstChildOfClass("Tool")
local Tool_debounce = false

Tool.Handle.Touched:Connect(function(hit)
    if hit.Name == "HumanoidRootPart" then
        if not Tool_debounce then
            Tool:Activate()
            Tool_debounce = true
           delay(1, function()
                Tool_debounce = false
            end)
        end
    end
end)