Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make this hitbox and damage script not damage the player, but the enemy player?

Asked by
Jirozu 71
8 years ago

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 = Vector3.new(1.3, 1.3, 1.3)
08 
09        local Weld = Instance.new("Weld", Hitbox)
10        Weld.Part0 = Hitbox
11        Weld.Part1 = Character.LeftHand
12        Weld.C0 = Weld.C0 * CFrame.new(0, 0, 0)
13 
14        --Damage
15        Hitbox.Touched:connect(function(p)
View all 29 lines...

1 answer

Log in to vote
0
Answered by 8 years ago

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...

1Player = game.Players:GetPlayerFromCharacter(p.Parent)
2if 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.

Ad

Answer this question