How do I make a bayonet script?
I was trying to make a gun with a bayonet and i wanted it to do damage, the script I have in it is called "BayonetScript"
001 | r = game:service( "RunService" ) |
007 | local slash_damage = 15 |
008 | local lunge_damage = 45 |
010 | sword = script.Parent.Handle |
014 | local SlashSound = Instance.new( "Sound" ) |
016 | SlashSound.Parent = sword |
017 | SlashSound.Volume = . 7 |
019 | local LungeSound = Instance.new( "Sound" ) |
021 | LungeSound.Parent = sword |
022 | LungeSound.Volume = . 6 |
024 | local UnsheathSound = Instance.new( "Sound" ) |
026 | UnsheathSound.Parent = sword |
027 | UnsheathSound.Volume = 1 |
029 | function DarkKill(character, humanoid, attacker) |
031 | if (character:FindFirstChild( "ForceField" ) ~ = nil ) then return end |
033 | local childs = character:GetChildren() |
037 | tagHumanoid(humanoid, attacker) |
041 | if (childs [ i ] .className = = "Part" ) then |
042 | colors [ i ] = childs [ i ] .BrickColor |
043 | childs [ i ] .BrickColor = BrickColor.new( 26 ) |
044 | childs [ i ] .CanCollide = true |
045 | childs [ i ] .Anchored = true |
052 | if (childs [ i ] .className = = "Part" ) then |
053 | local b = Instance.new( "BodyVelocity" ) |
054 | b.velocity = Vector 3. new(math.random() - . 5 , 0 , math.random() - . 5 ).unit * 80 |
055 | b.maxForce = Vector 3. new( 1 e 5 , 1 e 5 , 1 e 5 ) |
061 | if (childs [ i ] .className = = "Part" ) then |
062 | childs [ i ] .Anchored = false |
079 | local humanoid = hit.Parent:findFirstChild( "Monster" ) |
080 | local vCharacter = Tool.Parent |
081 | local vPlayer = game.Players:playerFromCharacter(vCharacter) |
082 | local hum = vCharacter:findFirstChild( "Humanoid" ) |
083 | if humanoid~ = nil and humanoid ~ = hum and hum ~ = nil then |
086 | local right_arm = vCharacter:FindFirstChild( "Right Arm" ) |
087 | if (right_arm ~ = nil ) then |
088 | local joint = right_arm:FindFirstChild( "RightGrip" ) |
089 | if (joint ~ = nil and (joint.Part 0 = = sword or joint.Part 1 = = sword)) then |
090 | hum.Health = hum.Health + (damage * . 5 ) |
091 | if humanoid.Health > damage then |
092 | tagHumanoid(humanoid, vPlayer) |
093 | humanoid:TakeDamage(damage) |
095 | untagHumanoid(humanoid) |
097 | DarkKill(humanoid.Parent, humanoid, vPlayer) |
108 | function tagHumanoid(humanoid, player) |
109 | local creator_tag = Instance.new( "ObjectValue" ) |
110 | creator_tag.Value = player |
111 | creator_tag.Name = "creator" |
112 | creator_tag.Parent = humanoid |
115 | function untagHumanoid(humanoid) |
116 | if humanoid ~ = nil then |
117 | local tag = humanoid:findFirstChild( "creator" ) |
126 | damage = slash_damage |
128 | local anim = Instance.new( "StringValue" ) |
129 | anim.Name = "toolanim" |
135 | damage = lunge_damage |
139 | local anim = Instance.new( "StringValue" ) |
140 | anim.Name = "toolanim" |
145 | force = Instance.new( "BodyVelocity" ) |
146 | force.velocity = Vector 3. new( 0 , 10 , 0 ) |
147 | force.Parent = Tool.Parent.Torso |
155 | damage = slash_damage |
159 | Tool.GripForward = Vector 3. new(- 1 , 0 , 0 ) |
160 | Tool.GripRight = Vector 3. new( 0 , 1 , 0 ) |
161 | Tool.GripUp = Vector 3. new( 0 , 0 , 1 ) |
165 | Tool.GripForward = Vector 3. new( 0 , 0 , 1 ) |
166 | Tool.GripRight = Vector 3. new( 0 ,- 1 , 0 ) |
167 | Tool.GripUp = Vector 3. new(- 1 , 0 , 0 ) |
170 | function swordAcross() |
177 | function onActivated() |
179 | if not Tool.Enabled then |
185 | local character = Tool.Parent; |
186 | local humanoid = character.Humanoid |
187 | if humanoid = = nil then |
188 | print ( "Humanoid not found" ) |
194 | if (t - last_attack < . 2 ) then |
213 | script.Parent.Activated:connect(onActivated) |
214 | script.Parent.Equipped:connect(onEquipped) |
217 | connection = sword.Touched:connect(blow) |