Heya!
I’m trying to make a sword script from scratch, as me and a friend are collaborating to make an RPG game. However, no matter what I do, it seemingly won’t stop having the same bug: the script deals damage multiple times before the function ends.
t = script.Parent
hbox = t.Hitbox
han = t.Handle
t.Activated:Connect(function()
print("setting touch")
hbox.CanTouch = true --make sure it can actually HIT PEOPLE
print("waiting...")
task.wait(0.002) --make sure it doesnt blow up
hbox.Touched:Connect(function(hit)
print("turning off the freaking disentegration")
hbox.CanTouch = false --did it hit smth?
print("touch fired")
task.wait(0.25)
if hit.Parent:WaitForChild("Humanoid") ~= nil then --check to make sure we arent killing the AIR
print("it exists!")
local hum = hit.Parent:WaitForChild("Humanoid")
hum.Health = hum.Health - 15 --actual damage
end
end)
task.wait(1) --delay so hit detection lasts the whole animation
if hbox.CanTouch == true then hbox.CanTouch = false end -- check then make sure it doesnt kill everything
end)
BEFORE YOU SAY ANYTHING ABOUT IT NOT DAMAGING ON THE SERVER BECAUSE I DON’T HAVE EVENTS: I know. I’m testing it on local before I set up events.
…unless that’s the problem, in which case, I’m sorry.
Edit: Everything prints in console fine, besides spamming and clogging the output.