So I have a plane game. All the planes have guns. Shooting at the enemy planes wings activates a script that adds an image on to them and breaks them. The problem is that the plane guns bullets don't react with the wings script. the script in the wings works fine I tested it but something is wrong with the bullets. Heres the gun script

--wait()
local ball = script.Parent
local damage = 40

function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	
		
	if hit:GetMass() < 1 * 20 then
		if hit.Anchored == false then
			hit:BreakJoints()
		end
	end
	

	if humanoid ~= nil then
		tagHumanoid(humanoid)
		humanoid:TakeDamage(damage)
		wait(2)
		untagHumanoid(humanoid)
	end

	connection:disconnect()
	ball:remove()
end

function tagHumanoid(humanoid)
	-- todo: make tag expire
	local tag = ball:findFirstChild("creator")
	if tag ~= nil then
		local new_tag = tag:clone()
		new_tag.Parent = humanoid
	end
end


function untagHumanoid(humanoid)
	if humanoid ~= nil then
		local tag = humanoid:findFirstChild("creator")
		if tag ~= nil then
			tag.Parent = nil
		end
	end
end

connection = ball.Touched:connect(onTouched)

Heres the plane script

bin = script.Parent
plane = nil
hold = false
local debounce = false
local planedebounce = false
local stuntdebounce = false
local controlling = false
local currentspeed = 0
local turn = nil
fly = false

local missile = false
local shooting = false



function fire_MachineGun(gun_Source, player)
	while shooting == true do
		missile = true
		local guns = gun_Source:GetChildren()
				local vehicle = findPlane(script.Parent.Parent.Parent)
		for i = 1,#guns do
			if guns[i].Name == "MachineGun" and guns[i].className == "Part" then
				local shoot = Instance.new("Part")
				shoot.BrickColor = BrickColor.new("Bright yellow")
				shoot.formFactor = "Custom"
				shoot.Size = Vector3.new(0.4,0.4,6)
				shoot.CFrame = guns[i].CFrame * CFrame.new(0,0,-50)
				shoot.Name = "Bullet"
				local d = game:GetService("Debris")
				d:AddItem(shoot,5)

				local force = Instance.new("BodyVelocity")
				force.Parent = shoot
				force.Name = "Move"
				force.velocity = guns[i].CFrame.lookVector * 750

				local creator = Instance.new("ObjectValue")
				creator.Name = "creator"
				creator.Value = player
				creator.Parent = shoot

				local shot = script:findFirstChild("GunScript"):clone()
				shot.Disabled = false
				shot.Parent = shoot

				shoot.Parent = Workspace
			end
		end
		vehicle.FireGun:play()
		wait(0.15)
	end
	missile = false
end

function computeDirection(vec)
	local lenSquared = vec.magnitude * vec.magnitude
	local invSqrt = 1 / math.sqrt(lenSquared)
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

function move(point, engine)
	local origincframe = engine:findFirstChild("Direction").cframe
	size = engine.Size

	target = engine.Position+((point - engine.Position).unit*100)
	local dir = (target - engine.Position).unit
	local spawnPos = engine.Position
	left = engine.CFrame*CFrame.new(-size.x/2, 0, 0).p
	right = engine.CFrame*CFrame.new(size.x/2, 0, 0).p
	md = (target - engine.Position).magnitude

	foebmd = engine.CFrame*CFrame.new(0, 0, -md).p
	toleft = (target -left).magnitude
	toright = (target -right).magnitude
	rot = ((foebmd - target).magnitude/10)
	local pos = spawnPos + (dir * 1)
	turn = math.rad((rot/10)*engine.TiltFactor.Value)
	if turn > math.rad(89) then
	turn = math.rad(89)
	end
	if toleft< toright and toleft >rot then
		engine:findFirstChild("Direction").cframe = CFrame.new(pos,  pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, turn)
	elseif toleft > toright and toright >rot then
		engine:findFirstChild("Direction").cframe = CFrame.new(pos,  pos + dir)*CFrame.fromEulerAnglesXYZ(0, 0, -turn)
	else
		engine:findFirstChild("Direction").cframe = CFrame.new(pos,  pos + dir)
	end
	engine:findFirstChild("Direction").P = engine.TurnSpeed.Value
end

function findPlane(player)
	local list = player.Character:GetChildren()
	for x = 1, #list do
		if (list[x].Name == "AircraftSeat") then
			return list[x]
		end
	end
	return nil
end

function onButton1Down(mouse)
	local vehicle = findPlane(script.Parent.Parent.Parent)
	if vehicle ~= nil and debounce == false and planedebounce == false then
	if fly == false and taxi == false then return end
	debounce = true

	controlling = true

	while true do
		wait()
		local engine = vehicle
		local position = mouse.Hit
		local target = position.p
		move(target, engine)
		if planedebounce == true or
		controlling == false then break end
	end
	wait(0.1)
	debounce = false
	end
end

function onButton1Up(mouse)
	controlling = false
end

function onSelected(mouse)
	mouse.Icon = "http://www.roblox.com/asset/?id=7419350"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Button1Up:connect(function() onButton1Up(mouse) end)
	mouse.KeyDown:connect(onKeyDown)
	mouse.KeyUp:connect(onKeyUp)
	mouse.Move:connect(function() Fly(mouse) end)
	mouse.Idle:connect(function() Fly(mouse) end)
end

function Fly(mouse)
	local vehicle = findPlane(script.Parent.Parent.Parent)
	if (vehicle==nil) then return end
	vehicle.Thrust.velocity = (vehicle.CFrame.lookVector * currentspeed) + Vector3.new(0,vehicle.LiftTrim.Value/100,0)
end

function onKeyDown(key)
	if (key~=nil) then
		key = key:lower()
		local vehicle = findPlane(script.Parent.Parent.Parent)
		if (vehicle==nil) then return end
			if key == "y" then
				fly = true
				vehicle.Startup:Play()
				vehicle.Starter1.Smoke.Enabled = true
				wait(1)
				vehicle.Starter1.Smoke.Enabled = false
				vehicle.Fly:Play()
				vehicle.Direction.cframe = vehicle.CFrame
				vehicle.Direction.maxTorque = Vector3.new(4e3,4e3,4e3)
				vehicle.Thrust.maxForce = Vector3.new(9e20,9e20,9e20)
				vehicle.Speed.Value = vehicle.MaxSpeed.Value
				while fly == true do
					if currentspeed < vehicle.Speed.Value then
						currentspeed = currentspeed + 1
					elseif currentspeed > vehicle.Speed.Value then
						currentspeed = currentspeed - 1
					end
					if vehicle.Acceleration.Value > 1000 then vehicle.Acceleration.Value = 1000 end
					wait((1-(vehicle.Acceleration.Value/1000))+0.01)
					if fly == false then break end
				end
			end
			if key == "x" then
				fly = false
				currentspeed = 0
				vehicle.Direction.maxTorque = Vector3.new(0,0,0)
				vehicle.Thrust.maxForce = Vector3.new(0,0,0)
			end
			if key == "l" and fly == true then
				vehicle.Direction.maxTorque = Vector3.new(4e3,0,4e3)
				local frame = vehicle:FindFirstChild("OriginCFrame")
				if frame ~= nil then
				vehicle.Direction.cframe = frame.Value
				end
				wait(2)
				vehicle.Direction.cframe = vehicle.CFrame
				vehicle.Direction.maxTorque = Vector3.new(4e3,4e3,4e3)
			end 
			if key == "s" then
				if vehicle.Speed.Value > vehicle.MinSpeed.Value then
					vehicle.Speed.Value = vehicle.Speed.Value - 10
				end
			end
			if key == "w" then
				if vehicle.Speed.Value < vehicle.MaxSpeed.Value then
					vehicle.Speed.Value = vehicle.Speed.Value + 10
				end
			end
			if key == "f" and missile == false then
				shooting = true
				fire_MachineGun(vehicle, bin.Parent.Parent)
			end
	end
end

function onKeyUp(key)
	if (key~=nil) then
		key = key:lower()
		if key == "f" then
			shooting = false
		end
		local vehicle = findPlane(script.Parent.Parent.Parent)
		if (vehicle==nil) then return end
	end
end

bin.Selected:connect(onSelected)
bin.Deselected:connect(onDeselected)

HERES THE WING Break SCRIPT

function onTouched(hit) 
	if hit:GetMass() > 1 * 20 then
	script.Parent.Parent.Parent.AircraftSeat.Crash:Play()
	script.Parent.Parent.Parent.AircraftSeat.Fly:Remove()
	script.Parent.Parent.Parent.AircraftSeat.Direction:Remove()
	script.Parent.Parent.Parent.AircraftSeat.Thrust:Remove()
	script.Parent:BreakJoints()
	script:Remove()
	end
end

script.Parent.Touched:connect(onTouched)

And heres the wing image script

function onTouch(hit)

		if hit.Name == "Bullet" then
			if script.Parent.Decal1.Texture == "http://www.roblox.com/asset/?id=79618928" then
			script.Parent.Decal1.Texture = "http://www.roblox.com/asset/?id=81793907"
			script.Parent.Decal2.Texture = "http://www.roblox.com/asset/?id=81793907"
			script.Parent.BH2.Disabled = false
			script:Remove()
			end
		end
end

script.Parent.Touched:connect(onTouch)

Any idea on how to fix this?

1 comment

1

Remove() is deprecated, use Destroy()