Hi, so basically im making an ability for a sword where it does multiple slashes continuously. For some reason though, even after i did the if statement for debounce, and set it to true, it still damages the player? I would really appreciate help. Thanks!
Heres the script in serverscript service that gets activated from a remote event:
game.ReplicatedStorage.standinghere.OnServerEvent:Connect(function(player)
local debounce1 = false
local debounce2 = false
local debounce3 = false
local char = player.Character
local sword = player.Character:FindFirstChild("HF-Blade")
wait(0.5)
sword.Handle.hitbox.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if debounce1 == false then
debounce1 = true
Hit.Parent.HumanoidRootPart.Anchored = true
local hp = game.Players:GetPlayerFromCharacter(Hit.Parent)
local sw = Hit.Parent:FindFirstChildOfClass("Tool") or hp.Backpack:FindFirstChildOfClass("Tool")
if sw:FindFirstChild("Script") then
sw.Script.Disabled = true
end
if sw:FindFirstChild("Ability") then
sw.Ability.Disabled = true
end
game.ReplicatedStorage.Bump:FireAllClients()
sword.Handle.hitt:Play()
local anim = Instance.new("Animation")
anim.AnimationId = "https://www.roblox.com/asset/?id=10215173320"
local playAnim = char.Humanoid:LoadAnimation(anim)
playAnim:Play()
wait(0.4)
local a = sword.Handle.OrangeSpark:Clone()
local b = sword.Handle.WhiteSpark:Clone()
local c = sword.Handle.Wisps:Clone()
a.Parent = Hit.Parent.HumanoidRootPart
b.Parent = Hit.Parent.HumanoidRootPart
c.Parent = Hit.Parent.HumanoidRootPart
a.Enabled = true
b.Enabled = true
c.Enabled = true
sword.Handle.raidensword:Play()
sword.Handle.Touched:Connect(function(hit) -- The part that still damages
if hit.Parent:FindFirstChild("Humanoid") then
if debounce2 == false then
debounce2 = true
sword.Handle.ow:Play()
hit.Parent.Humanoid:TakeDamage(dph)
wait(.1)
debounce2 = false
end
end
end)
wait(4.22)
debounce2 = true
-- not important below
a.Enabled = false
b.Enabled = false
c.Enabled = false
sword.Handle.raidensword:Stop()
sword.Handle.PLAYTIME:Play()
wait(1.4)
sword.Handle.STAB:Play()
sword.Handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce3 == false then
debounce3 = true
hit.Parent.Humanoid:TakeDamage(stabdmg)
game.ReplicatedStorage.Boom:FireAllClients()
a.Enabled = true
b.Enabled = true
c.Enabled = true
wait(0.4)
a.Enabled = false
b.Enabled = false
c.Enabled = false
wait(1)
a:Destroy()
b:Destroy()
c:Destroy()
end
end
end)
end
end
end)
end)

3 comments
It works! Thank you so much! The only reason i didnt do it before is because the ability is meant to be used over and over again, but i just made it make the value true before it uses them, so thanks! Also, im still new to scripting so do you mind explaining what the Disconnect function does?
The disconnect function does as the name implies. It disconnects a connected event from running its connected function. You can read more about it here: https://developer.roblox.com/en-us/articles/events
Thanks!