Hi I need some help with making a sword, that doesn't one hit players. I tried fixing it so many times but It wont work. I need some help! Here is my script:
01 | local sword = script.Parent |
02 | debounce = 2 |
03 | notfree = false |
04 |
05 |
06 | local function slash() |
07 | if notfree = = false then |
08 |
09 | sword.blade.Touched:Connect( function (hit) |
10 | human = hit.Parent:FindFirstChild( "Humanoid" ) |
11 | if human then |
12 | human:TakeDamage( 20 ) |
13 | end |
14 | notfree = true |
15 | end ) |
Just change
1 |
human:TakeDamage(20)
1 |
to
1 |
human:TakeDamage(100)
1 |
The problem is that your sword is hitting the other player multiple times when it slashes.
There is a simple fix for this but sometimes it can be inconsistent.
The fix is adding a cooldown when the sword touches a player. This makes it so that if your sword touches a player, it will start the cooldown and all the following touches will be ignored until the cooldown ends.
01 | local sword = script.Parent |
02 | debounce = 2 |
03 | cooldown = false |
04 | notfree = false |
05 |
06 |
07 | local function slash() |
08 | if notfree = = false then |
09 |
10 | sword.blade.Touched:Connect( function (hit) |
11 | human = hit.Parent:FindFirstChild( "Humanoid" ) |
12 | if human then |
13 | if cooldown = = false then |
14 | cooldown = true |
15 | human:TakeDamage( 20 ) |
If this doesn't work then make the waiting time for the cooldown longer