Hi, I'm trying to make an ability for a sword which does a lot of damage in one hit. It does the damage, but it keeps damaging the opponent even when you're just holding the sword over them. Ive tried making it wait and set the takedamage script to 0 but it still won't work. Help would be much appreciated!
here is the script in server script service which gets activated once a remote event is fired:
game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player) local char = player.Character local bat = char:FindFirstChild("Bat") wait(1.2) bat.Handle.Bonk:Play() bat.Handle.bat_hit:Play() bat.Handle.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= player.Name then hit.Parent.Humanoid:TakeDamage(1.5) end end end) wait(.5) bat.Handle.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if hit.Parent.Name ~= player.Name then hit.Parent.Humanoid:TakeDamage(0) end end end) end)
What's up?
I have found a pretty solid solution to your question.
I have answered this in a similar question of yours (https://scriptinghelpers.org/questions/129322/sword-not-knocking-back-players-when-used), but I will help again anyhow.
To start off, :TakeDamage() won't stop them taking damage! :TakeDamage(0) just means it won't make them loose health.
Anyhow, DEBOUNCE IS HERE TO SAVE THE DAY!!!
Inside your script:
game.ReplicatedStorage.Bat.OnServerEvent:Connect(function(player,bat) local debounce = false local char = player.Character wait(1.2) bat.Handle.Bonk:Play() bat.Handle.bat_hit:Play() bat.Handle.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then if hit.Parent.Name ~= player.Name then hit.Parent.Humanoid:TakeDamage(1.5) end end end) wait(.5) debounce = true end)