Haven’t looked at the whole script yet but you are creating a new .Touched event every time that tool is equipped. Consider moving that connection outside of Tool.Activated? Also, you’re using the debounce on Tool.Activated… not on hitbox.Touched. On another look, what do you want to achieve exactly?
Mhm, and do you only want to check the touch if that tool has been activated? Or do you want to check if parts are touching it if the tool has been equipped? I think you want the latter but just confirming.
The Activated event is creating a new Touched connection every time you use the tool.
To get around this you can use the debounce in reverse for a seperate touched connection outside of the activated connection.
Not sure if this is what you need but give it a try. I would consider raycasting over this method, but it might be what you’re looking for!
local Tool = script.Parent.Parent
local hitbox = Tool.Handle.HitBox
local debounce = false
local Cooldown = 10 --Change this to the cooldown value
local function GetTouchingParts(part)
local Connection = part.Touched:Connect(function() end)
local Parts = part:GetTouchingParts()
Connection:Disconnect()
return Parts
end
Tool.Activated:Connect(function()
if debounce then return end
debounce = true
Tool.Handle.Material = Enum.Material.Neon
Tool.Handle.BrickColor = BrickColor.new("Institutional white")
for _,wow in next, GetTouchingParts(hitbox) do
if wow.Name == "HumanoidRootPart" then
task.spawn(function()
print(wow)
local HRP = wow.Parent:FindFirstChild("HumanoidRootPart")
local Humanoid = wow.Parent:FindFirstChild("Humanoid")
Humanoid.PlatformStand = true
local BodyVelocity = Instance.new("BodyVelocity", HRP)
BodyVelocity.Velocity = Vector3.new(math.huge,math.huge,math.huge)
Tool.Handle.Particle.Enabled = true
Tool.Handle.Particle2.Enabled = true
Tool.Handle.lightning_strike:Play()
local sound = script.Parent.idloveyou:Clone()
sound.Parent = wow.Parent:FindFirstChild("HumanoidRootPart")
sound.PlayOnRemove = true
sound:Destroy()
game.ReplicatedStorage.Remotes.Camera.SmallExplosion:FireAllClients()
task.wait(1)
Tool.Handle.Particle.Enabled = false
Tool.Handle.Particle2.Enabled = false
Tool.Handle.Material = Enum.Material.Wood
Tool.Handle.BrickColor = BrickColor.new("Dirt brown")
BodyVelocity:Destroy()
Humanoid.PlatformStand = false
task.wait(10.479)
Tool.Handle.Material = Enum.Material.Neon
Tool.Handle.BrickColor = BrickColor.new("Institutional white")
end)
end
end
task.wait(Cooldown)
debounce = false
end)
Edit: It’s messy but that’s because I haven’t really read through the code you’ve provided. I also suggest breaking the loop if wow.Name == 'HumanoidRootPart. But I am all doing it on assumptions. Let me know if something isn’t how you wanted it.
And to confirm, what the script I provided you does is that when you activate a tool, it checks all the parts it’s hitting only at that moment and then runs your code. Waits until cooldown is over before you can re-activate. Just confirming since looking back at your code, it seems like you may have wanted something like:
Tool activated, checking for Touched objects for 11 seconds. Cooldown ends after those 11 seconds and the .Touched stops checking for those objects.
This is the exact reason why you should use magnitude.
:Touched
is not very reliable. It can make it “double-click” or in this example “double touch.”
Now if you use a debounce 99% of the time it won’t “double touch.”
Here is my solution while still using :Touched, :
local Tool = script.Parent.Parent
local hitbox = Tool.Handle.HitBox
local debounce = true
Tool.Activated:Connect(function()
if debounce == false then
return
end
debounce = false
Tool.Handle.Material = Enum.Material.Neon
Tool.Handle.BrickColor = BrickColor.new("Institutional white")
hitbox.Touched:Connect(function(wow)
if wow.Name == "HumanoidRootPart" then
print(wow)
local HRP = wow.Parent:FindFirstChild("HumanoidRootPart")
local Humanoid = wow.Parent:FindFirstChild("Humanoid")
Humanoid.PlatformStand = true
local BodyVelocity = Instance.new("BodyVelocity", HRP)
BodyVelocity.Velocity = Vector3.new(math.huge,math.huge,math.huge)
Tool.Handle.Particle.Enabled = true
Tool.Handle.Particle2.Enabled = true
Tool.Handle.lightning_strike:Play()
local sound = script.Parent.idloveyou:Clone()
sound.Parent = wow.Parent:FindFirstChild("HumanoidRootPart")
sound.PlayOnRemove = true
sound:Destroy()
game.ReplicatedStorage.Remotes.Camera.SmallExplosion:FireAllClients()
wait(1)
Tool.Handle.Particle.Enabled = false
Tool.Handle.Particle2.Enabled = false
Tool.Handle.Material = Enum.Material.Wood
Tool.Handle.BrickColor = BrickColor.new("Dirt brown")
BodyVelocity:Destroy()
Humanoid.PlatformStand = false
wait(10.479)
Tool.Handle.Material = Enum.Material.Neon
Tool.Handle.BrickColor = BrickColor.new("Institutional white")
debounce = true
end
end)
end)