What I’m asking is how would I make a tool that damages the other player when it’s activated.
I have thought of making two scripts and having the damage script disabled and then enabled for 2 seconds when the tool is activated. But I don’t think this is very efficient.
Should I try something with a variable such as:
Activated = false.
1 Like
Can you be a bit more specific? Is this a sword or something? How is it supposed to damage the “other player?”
And also, please share the code you’ve written
That is the code I have so far.
tool = script.Parent
tool.Activated:Connect(function()
candamage = true
wait(1)
candamage = false
end)
tool.Handle.Touched:Connect(function(touch)
if candamage == true then
end
end)
But can you specify? Is this supposed to hit once before deactivating or allow hit as many times throughout a 1 sec time span?
candamage = false
tool = script.Parent
tool.Activated:Connect(function()
candamage = true
wait(1)
candamage = false
end)
tool.Handle.Touched:Connect(function(touch)
if candamage == true then
local hum = touch.Parent:findFirstChild("Humanoid")
if hum~=nil then
hum:TakeDamage(10)
end
end
end)
This would be for the option 2 that I mentioned
This would work, but you can do it better! This tutorial is pro.
Although I prefer using raycast hitbox.
When the tool is activated and it touches someone I want it to damage them once, it can damage up to 3 people in one hit. I’m using this as a suggestion but if you have ever played slap battles like that.
You forgot the debounce btw. This would make it so you can’t spam.
This doesn’t help what I’m trying to find a solution for.
tool.Handle.Touched:Connect(function(touch)
if candamage == true then
local hum = touch.Parent:findFirstChild("Humanoid")
if hum then
hum:TakeDamage(10)
end
end
end)
Couldn’t I just add candamage = false to the end.
But how would I add a cooldown using debounce so that the player can’t spam click?
this is a reworked version of the other dudes
local tool = script.Parent
local cooldown = false
tool.Activated:Connect(function()
if cooldown == false then
cooldown = true
wait(3)
cooldown = false
wait
end
end)
tool.Handle.Touched:Connect(function(touch)
if cooldown == true then
local hum = touch.Parent:findFirstChild("Humanoid")
if hum~=nil then
hum:TakeDamage(10)
end
end
end)
this was written on the dev forum so if it dont work its probably cause of that.
remove the wait on the bottom
This text will be blurred
The cooldown doesn’t work though.
I’m not on pc, I cannot help currently.
Do you have an animation? If not you have to move again to touch.
Never mind, I found a solution.