This function is supposed to produce a bullet fired from a plane’s machine gun when fired.
It fires, but the bullet spawns too close to the plane, and has a high chance of breaking the place, despite some if statements I have to account for it.
Here’s the function:
function FireBullet(Player,Shoot)
if Shoot then
local Part = Instance.new("Part")
Part.BrickColor = BrickColor.new("Bright yellow")
Part.Name = "Bullet"
Part.CanCollide = false
Part.FormFactor = "Symmetric"
Part.Size = Vector3.new(5,5,3)
Part.BottomSurface = "Smooth"
Part.TopSurface = "Smooth"
local Mesh = Instance.new("BlockMesh")
Mesh.Parent = Part
Mesh.Scale = Vector3.new(1/25,1/25,1)
local BV = Instance.new("BodyVelocity")
BV.Parent = Part
BV.maxForce = Vector3.new(math.huge,math.huge,math.huge)
local PlaneTag = Instance.new("ObjectValue")
PlaneTag.Parent = Part
PlaneTag.Name = "PlaneTag"
PlaneTag.Value = Vehicle
Part.CFrame = Shoot.CFrame * CFrame.new(0, 0, -55)
BV.velocity = (Engine.BodyVelocity.Velocity) + (Part.CFrame.lookVector * 2000) + (Vector3.new(0,0.15,0))
Part.Parent = game.Workspace
Part.Touched:connect(function(Object) --This lets me call the "Touched" function, which means I don't need an external script
if (not Object:IsDescendantOf(Chara)) and (not Object:IsDescendantOf(Vehicle)) then
local HitHumanoid = Object.Parent:findFirstChild("Humanoid")
if HitHumanoid~=nil then
HitHumanoid:TakeDamage(100) --This only damges the player if they don't have a forcefield
local CreatorTag = Instance.new("ObjectValue")
CreatorTag.Name = "creator"
CreatorTag.Value = Player
CreatorTag.Parent = HitHumanoid
else
Object:BreakJoints()
end
end
end)
delay(3,function() Part:Destroy() end)
end
end