Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Sword still damaging players even when it shouldn't?

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)

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you so much! I really cant thank you enough for this. I've been waiting for so long to get an answer. Thank you!

0

Any time! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.