AI Helicopter Movement Malfunctioning & Bugging

Alrighty, hello.

I am working on an AI Helicopter Project, (inspired by Call of Duty)
Long story short, it’s bugging.

I reached out to the DevForum for requiring help.

Watch the video to understand the bug:

As you see I get a little bit teleported in the ground (And sometimes I get flinged out of the map bruh)
Anyways, the main issue is that once the helicopter gets tweened, the rotors stop spinning. I want it so they keep spinning.

All resources down below.

Top & Back Rotor Script:

while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,1,0)
	wait()
end

Left & Right Seat Script:

seat = script.Parent
anim = seat.Animation

function Added(Descendant)
	if (Descendant.ClassName == "Weld") then
		local Humanoid = Descendant.Part1.Parent:FindFirstChild("Humanoid")

		if Humanoid ~= nil then
			Animation = Humanoid:LoadAnimation(anim)
			Animation:Play()
		end
	end
end

function Removing(Descendant)
	if Animation ~= nil then
		Animation:Stop()
		Animation:Remove()
	end
end

seat.ChildAdded:Connect(Added)
seat.ChildRemoved:Connect(Removing)

Tweening Helicopter Script:

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Destinations = game.Workspace.Helicopter.DestinationPoints
local AIHelicopter = game.Workspace.Helicopter.HeliNoRotor

local NewPoint = 1
local Speed = 50

local debounce = false

AIHelicopter.PrimaryPart = AIHelicopter.Center
AIHelicopter:SetPrimaryPartCFrame(AIHelicopter.Center.CFrame)

function GetTime(Distance, Speed)
	local Time = Distance / Speed
	return Time
end

function WeldAIHelicopter()
	for i = 1, #AIHelicopter:GetChildren() do
		if AIHelicopter:GetChildren()[i] ~= AIHelicopter.PrimaryPart then
			local Weld = Instance.new("WeldConstraint")
			Weld.Part0 = AIHelicopter:GetChildren()[i]
			Weld.Part1 = AIHelicopter.PrimaryPart
			Weld.Parent = AIHelicopter.PrimaryPart

			AIHelicopter:GetChildren()[i].Anchored = false
		end
	end
end

function AutoControlAIHelicopter()
	NewPoint += 1

	if not Destinations:FindFirstChild(""..NewPoint) then
		wait(5)
		NewPoint = 1
		AIHelicopter.PrimaryPart.CFrame = Destinations:FindFirstChild("1").CFrame
		wait(10)
	end

	local NextPoint = Destinations[""..NewPoint]
	local Distance = (AIHelicopter.PrimaryPart.Position - NextPoint.Position).Magnitude
	local Time = GetTime(Distance, Speed)

	local TweenInformation = TweenInfo.new(Time, 
		Enum.EasingStyle.Linear, 
		Enum.EasingDirection.Out, 0, false, 0)

	local Tween = TweenService:Create(AIHelicopter.PrimaryPart, TweenInformation, {CFrame = NextPoint.CFrame})
	Tween:Play()
	Tween.Completed:Wait()

	AutoControlAIHelicopter()

end

--Finalization
wait(15)
WeldAIHelicopter()
AutoControlAIHelicopter()

How workspace looks like:

image

These are all the resources you need to assist me.

I find this very weird and I think it is 100% possible to fix.

Thank you so much for reading, and I hope someone helps me with this problem.
My friend @voozy_v tried to help, but also failed.

Thanks.

is the top and back motor welded onto the helicopter? your top and back script would work when its still but it seems like it will bug when the helicopter moves…

Rotor’s are indeed welded. See edit above to see what my explorer looks like.

try instead of using weld constraints and CFraming the one thing use Motor6ds. If you have Moon Animator you can easy weld (to join them in place) then instead of changing their CFrame, change the M6d C0.

Don’t have moon animator, I’m not trying to make a bigger problem out of this but it has to be fixable by just scripting it. I don’t feel like using an animator to rig / weld it. I don’t see a need.

Alright, So, Imma try to make a script to do what Moon Animator does

local Motor = Instance.new("Motor6D")
local Primary = script.Parent.Parent.PrimaryPart

Motor.Parent = script.Parent
Motor.Part0 = Primary
Motor.Part1 = script.Parent
Motor.C0 = script.Parent.CFrame * Primary.CFrame:Inverse()

That makes a motor and SHOULD position it right, paste this in your part then go into your game, copy the model, leave and paste it in, Its basic rigging, but its exactly how you fix your problem, (also disable your movement scripts)

Then all you need to do is

while true do
	script.Parent.MotorName.C0 = script.Parent.MotorName.C0 * CFrame.fromEulerAnglesXYZ(0,1,0)
	wait()
end
1 Like

Thing is, the roters don’t have a primary part. It’s just a part that sticks to the heli.

Let me try it tho, I’m very unsure if it works. I’ll get back to you later.

I tried to make it the model’s primary part so you can weld it to the center

Sorry but where do I exactly paste this?

in a script inside the part, Im about 90% sure it works, also disable your spinny script cuz movement breaks m6ds

Tried, didn’t work.

ANy other option…?

Could we see a place file? Would you feel comfortable sharing that with the devforum? At least, for me, I would need it to be able to assist.

For the rotation of the helicopter blades, you can just use a hingcontraint, and set it to Motor. You do not need a script. HingeConstraint | Roblox Creator Documentation

I don’t feel comfortable. If you have discord I may add you and we can discuss there.

From what I can gather, this line is resulting in the teleport into the ground:

From there, the tween is playing. You may have to change the way the helicopter blades rotate, through HingConstraints as I mentioned. The reason they stop rotating was:

You weld the blades in place, breaking the tween (keep in mind, this is just a hypothesis. I cannot test)

Not sure. It only executes that once there’s no other destinations left.

After it reaches it end point, it’ll get tped back.

This has nothing to do with the start.

Okay, I didn’t realize. You can add a simple line in at the end, once the tween stops:

HeliModel.PrimaryPart.CFrame = FinalPart.CFrame -- with HeliModel being your helicopter model, and FinalPart being the final destination part.

Wait I didn’t realize that’s what’s breaking it!

LOL thanks for saying. I may find my solution from there? Not sure if I am able to initalize a script after welding.

All you have to do is check if the parts you want to weld are the right parts.

function WeldAIHelicopter()
	for i = 1, #AIHelicopter:GetChildren() do
		if AIHelicopter:GetChildren()[i] ~= AIHelicopter.PrimaryPart and AIHelicopter:GetChildren()[i] ~= AIHelicopter.RotorTop and AIHelicopter:GetChildren()[i] ~= AIHelicopter.RotorBack then -- Do a simple check
			local Weld = Instance.new("WeldConstraint")
			Weld.Part0 = AIHelicopter:GetChildren()[i]
			Weld.Part1 = AIHelicopter.PrimaryPart
			Weld.Parent = AIHelicopter.PrimaryPart

			AIHelicopter:GetChildren()[i].Anchored = false
		end
	end
end