This script attaches to a tool. It fires 3 projectiles and they should be destoryed when they hit something however it only destroys the last one. help would be greatly appreciated
local player = game.Players.LocalPlayer
local cooldown = false
cooldownTime = 2
function GetBullet()
local p = Instance.new("Part", workspace)
p.FormFactor = "Custom"
p.Size = Vector3.new(1, 1, 1)
p.BrickColor = BrickColor.Gray()
p.CanCollide = false
Instance.new("BodyVelocity", p)
return p
end
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:connect(function()
if cooldown == false then
cooldown = true
--Fire Projectile--
for x = 1, 3 do
mH = mouse.Hit
bullet = GetBullet()
bullet.CFrame = player.Character.Torso.CFrame * CFrame.new(player.Character.Torso.CFrame.lookVector * 2)
bullet.CFrame = CFrame.new(bullet.Position, mH.p)
bullet.BodyVelocity.velocity = bullet.CFrame.lookVector * 120
wait(.1)
bullet.Touched:Connect(function(hit)
print(hit.Name)
bullet:Destroy()
for _, child in pairs(hit.Parent:GetChildren())
do
if child:IsA("Humanoid") then
child:TakeDamage(100)
end
end
end)
end
wait(cooldownTime)
cooldown = false
end
end)
end)
