How would i make a part float while they are unanchored and make them be able to tween to something?

So I’m currently trying to make a Drone that attack enemies. What will it do is basically if it found an enemies it will tween to enemy head but a bit higher (,5,0). And the only issues im having here is that the drone is not floating AT ALL and the code seems to be very buggy. Is there a way i could do this?

Code currently that i have:

local ts = game:GetService("TweenService")

local function findtarget()
	local agrodistance = math.huge
	local target = nil
	for i, v in pairs(game.Workspace.Enemies:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso")
		if human and torso then

			if (goal.Position - torso.Position).magnitude < agrodistance then
				agrodistance = (goal.Position - torso.Position).magnitude
				target = torso
	return target

while task.wait() do
	local torso = findtarget()
	if torso then
		for i,v in pairs(unit:GetChildren()) do
			if v:IsA("MeshPart") or v:IsA("Part") then
				ts:Create(v, / 2),{Position = torso.Parent.Head.Position +,1.5,0)}):Play()
		if (unittorso.Position - torso.Position).magnitude < unitRange and torso.Parent.Humanoid.Health ~= 0 then
			local humanoid = torso.Parent:WaitForChild("Humanoid")
			local enemystats = require(torso.Parent.Stats)
			if enemystats.BulletDefense then
				pcall(function() torso.Parent.Humanoid:TakeDamage(unitStats.Damage * enemystats.BulletDefense) end)
				pcall(function() torso.Parent.Humanoid:TakeDamage(unitStats.Damage) end)

You can’t tween unanchored parts.

So either make it anchored or use humanoid to move it, which would be more preferable since ya can use pathfinding like SimplePath so it wouldn’t just go through walls and such

oh well most part will be collision less for the drone so simplepath or pathfinding wont be required so i’ll try anchoring it

The anchored make the drone Main part tweened well but the children aren’t. I replaced the tween with
ts:Create(unittorso, / 2),{CFrame = torso.Parent.Head.CFrame}):Play()
but the children doesn’t move and im using weld constraint

You can create a new Vector3Value to tween and then just listen to it’s .Changed event and use :PivotTo on the drone model to move it that way, so all of the children get dragged too

You could also make the primaryPart anchored and the children unanchored, then tween the primaryPart?


Doesn’t work that way sadly keystrokeskeystrokes

But i did that methood on my door

(I forgot to mention to weld children to primaryPart)

1 Like

I appreciate the recording you did for me and yea that teach me something. But the one method @computerph1_DEV gave to me works

Parent welds to primarypart,
Also part0 = primarypart
Part1 = childrenparts

Children should be unanchored
Parent shoule be anchored

this could be my first solution

You got the parenting wrong, all parts shoule be parented to model, not the primarypart

Unless it’s primarily the Weld that enables that, and not WeldConstraint, then it wouldn’t work either way. No matter to whom it parented to.

Also as you can see by the vid the part0 is root, while part1 is children parts

And yea the root part is anchored and children parts aren’t

Try this :

| > primaryPart (anchored)
| | weldConstaint (part0 = primaryPart, part1 =Child1 )
| | weldConstraint (part0 = primaryPart, part1 = child2)
| > Child1 (unanchored)
| > Child2 (unanchored

(I copy pasted the parenting from my working model)

Also tried just Weld earlier, doesn’t work with that either

Try this script (report errors if happens)

local ts = game:GetService("TweenService")
local model = --model

local goals = {Position = model.PrimaryPart.Position +,5,0)}

local ti =

local t = ts:Create(model.PrimaryPart, ti, goals)

It works for me

That does the exact same as the script that I wrote does, only tweens the primary part

1 Like

Try doing with CFrame, i did it in my door model, it works, here i did Position, cause CFrame and adding vector 3 value confuses me, so you could try doing that.

Yea CFrame works, btw you can add CFrame and Vector3 freely if that was your concern

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.