I haven’t tried that exactly yet, let me test it and see what happens
The codes debounce is used in a different way, I can assure you this works, as it was used in the example I provided.
No it wouldn’t, your script sets the debounce to false once and never to true again.
If you can read and understand code, you’d realize there’s a function that’ll change the debounce value from true to false in a short period of time, which results in one hit per swing.
The code didn’t work, I’m not sure if I put it in right but it just didn’t do any damage at all
local tool = script.Parent
local rs = game:GetService("RunService")
local canHit = false
local sword = script.Parent.Hitbox
function damage()
canHit = true
wait(0.5)
canHit = false
end
tool.LeftSwing.OnServerEvent:Connect(function()
sword.Touched:Connect(function(hit)
if canHit then
local found
found = hit.Parent:FindFirstChild("Humanoid")
if found then
found:TakeDamage(20)found = nil
else
print(found)
canHit = false
end
rs.Heartbeat:Wait()
canHit = false
end
end)
end)
Because the debounce is never set back to true, and there are some useless lines in there such as setting canHit to false twice, once in the else statement (if they didn’t hit a humanoid, which technically would be the same if the touched just fired in the first place and didn’t hit a humanoid, and you also set canHit to false even if found is true).
Call the damage function within the remote event.
tool.LeftSwing.OnServerEvent:Connect(function()
damage()
then the rest of your code.
I called damage right after the remote event and it didn’t work at all, it didn’t damage during the swing, but it damaged after the swing was finished it instantly killed the target.
Try putting the touch function outside of the remote event.
That wouldn’t really make a difference.
Let me write it up for you.
sword.Touched:Connect(function(hit)
if canHit then
local found
found = hit.Parent:FindFirstChild("Humanoid")
if found then
found:TakeDamage(20)found = nil
else
print(found)
canHit = false
end
rs.Heartbeat:Wait()
canHit = false
end
end)
tool.LeftSwing.OnServerEvent:Connect(function()
damage()
end)
Add a
wait(.2)
After BOTH:
tool.Hitbox.Touched:Connect(function(hit)
Make sure this is part of ur original code
This makes no difference whatsoever, the code still doesn’t work as intended
Try what I wrote for you, the way you wrote it was incorrect the first time.
Oh I’m sorry. I guess I misunderstood your problem. Sorry for the inconvenience.
Like this?
local tool = script.Parent
local rs = game:GetService("RunService")
local canHit = false
local sword = script.Parent.Hitbox
function damage()
canHit = true
wait(0.5)
canHit = false
end
tool.LeftSwing.OnServerEvent:Connect(function()
damage()
sword.Touched:Connect(function(hit)
if canHit then
local found
found = hit.Parent:FindFirstChild("Humanoid")
if found then
found:TakeDamage(20)found = nil
else
print(found)
canHit = false
end
rs.Heartbeat:Wait()
canHit = false
end
end)
end)
tool.LeftSwing.OnServerEvent:Connect(function()
damage()
end)
No, like this.
local tool = script.Parent
local rs = game:GetService(“RunService”)
local canHit = false
local sword = script.Parent.Hitbox
function damage()
canHit = true
wait(0.5)
canHit = false
end
sword.Touched:Connect(function(hit)
if canHit then
local found
found = hit.Parent:FindFirstChild("Humanoid")
if found then
found:TakeDamage(20)found = nil
else
print(found)
canHit = false
end
rs.Heartbeat:Wait()
canHit = false
end
end)
tool.LeftSwing.OnServerEvent:Connect(function()
damage()
end)
Still doesn’t work, it damages more than once per swing
Are you sure your remote event isn’t being called more than once?
Oh it works now, I see the issue, it was being called two times, it was calling itself in a loop I think but it works now thank you for the help