local AbleToDamage = true
local Damage = 30
local function Activated ()
script.Parent.Handle.Touched:Connect(function(Hit)
if AbleToDamage == true then
AbleToDamage = false
local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
Humanoid:TakeDamage(Damage)
end
wait(0.5)
AbleToDamage = true
end
end
end
script.Parent.Activated:Connect(Activated)
I noticed a problem, if you activate the tool it would listen for the touched event but after that it would still continue to listen for the touched event, so if your still holding the tool if someone touches it, it would damage them. I didn't really know what was wrong with it, so i tried to re-create it and while doing so i also tried to "improve" it.
You can try this, i added something so that it doesn't still listen for the touched event after its activated.
local AbleToDamage = true
local Damage = 30
local Connection
local function Activated ()
Connection = script.Parent.Handle.Touched:Connect(function(Hit)
if AbleToDamage == true then
AbleToDamage = false
local Humanoid = Hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
Humanoid:TakeDamage(Damage)
end
Connection:Disconnect()
wait(0.5)
AbleToDamage = true
else
Connection:Disconnect()
end
end)
end
script.Parent.Activated:Connect(Activated)
1 comment
Please provide a bit more background detail.