I made this hit box and damage script, and once it executes it damages the enemy player. But sometimes when i execute it, it damages the player, and not the enemy player, any help?
01 | --Hitbox to do damage |
02 | local Hitbox = Instance.new( "Part" , game.Workspace) |
03 | Hitbox.Anchored = false |
04 | Hitbox.CanCollide = false |
05 | Hitbox.Transparency = 1 |
06 | Hitbox.BrickColor = BrickColor.new( "Bright red" ) |
07 | Hitbox.Size = Vector 3. new( 1.3 , 1.3 , 1.3 ) |
08 |
09 | local Weld = Instance.new( "Weld" , Hitbox) |
10 | Weld.Part 0 = Hitbox |
11 | Weld.Part 1 = Character.LeftHand |
12 | Weld.C 0 = Weld.C 0 * CFrame.new( 0 , 0 , 0 ) |
13 |
14 | --Damage |
15 | Hitbox.Touched:connect( function (p) |
There is nothing checking to see what the hit player(p)
is. If the Hitbox
touches the Player, then it will deal damage accordingly.
Try adding...
1 | Player = game.Players:GetPlayerFromCharacter(p.Parent) |
2 | if Player = = --[===[put the player you don't want to get hurt here]===] then |
3 | --code |
If you're wondering why it doesn't hurt the enemy player when this happens, it's because you set the CanDamage.Value
to false while executing the damage code. Because the Player is hit first, the enemy player cannot take damage until the value is changed to true.