Why is my attack script not doing damage? The damage script normally works in other situations.
I have created a script that clones a part called "Damager" onto a hitbox. Damager should damage everything it touches, however for some reason it is not dealing damage when it is cloned. This is the script in damager:
2 | local human = hit.Parent:findFirstChild( "Humanoid" ) |
4 | human.Health = human.Health - 2 |
7 | script.Parent.Touched:connect(onTouched) |
It should work. This next script is the script that makes the attack work:
01 | local player = game.Players.LocalPlayer |
02 | repeat wait() until player.Character.Humanoid |
03 | local humanoid = player.Character.Humanoid |
04 | local mouse = player:GetMouse() |
08 | local anim = Instance.new( "Animation" ) |
11 | mouse.KeyDown:connect( function (key) |
13 | if script.Cooldown.Value = = false then |
14 | script.Cooldown.Value = true |
15 | local playAnim = humanoid:LoadAnimation(anim) |
18 | local Damage 1 = workspace.Clonables.Damager:Clone() |
19 | Damage 1. Parent = workspace |
20 | Damage 1. Position = player.Character.Hitbox 1. Position |
21 | Damage 1. Orientation = player.Character.Hitbox 1. Orientation |
22 | local weld 1 = Instance.new( "WeldConstraint" ) |
23 | weld 1. Parent = Damage 1 |
26 | weld 1. Part 1 = player.Character.Hitbox 1 |
30 | local Damage 2 = workspace.Clonables.Damager:Clone() |
31 | Damage 2. Parent = workspace |
32 | Damage 2. Position = player.Character.Hitbox 2. Position |
33 | Damage 2. Orientation = player.Character.Hitbox 2. Orientation |
34 | local weld 2 = Instance.new( "WeldConstraint" ) |
35 | weld 2. Parent = Damage 2 |
38 | weld 2. Part 1 = player.Character.Hitbox 2 |
42 | script.Cooldown.Value = false |
In theory, all of this should work perfectly, but for some reason it is not dealing damage. Does anyone know why? Please help.