How To Make Object Stay To Other Object's Left (Object/World Space or something?)

I have made a script that makes a little squad of dummies walk to wherever I click. I am trying to keep them in information with a table that puts the next dummy 2 studs away from the last but it is putting it 2 studs away on the Z axis all the time, I don’t know how to convert it so whatever angle the last dummy is looking, it will go to it’s left side.

Here is a video of what I mean:


As you can see depending on the axis they are facing, they will either line up behind or next to the last dummy. I want them to always go to the left.

Here is the script, the problem is to do with the LastPosition + Vector3.new(0,0,2). It’s something to do with it not being an object vector or something.

local AlreadyCommanded = {}

game.ReplicatedStorage.Click.OnServerEvent:Connect(function(Player, Position)
	local Dummies = script.Parent:GetChildren()
	for i,v in pairs(Dummies) do
		if v:IsA("Model") then
			local NumberOfCommandedSoFar = #AlreadyCommanded
			if NumberOfCommandedSoFar > 0 then
				local LastPosition = AlreadyCommanded[NumberOfCommandedSoFar]
				local NewPosition = LastPosition + Vector3.new(0,0,2)
				v.Humanoid:MoveTo(NewPosition)
				table.insert(AlreadyCommanded, NewPosition)
			else
				v.Humanoid:MoveTo(Position)
				table.insert(AlreadyCommanded, Position)
			end
		end
	end
	print(#AlreadyCommanded)
	AlreadyCommanded = {}
end)

Despite reading through the Object and World Space topic, I still don’t fully understand it. Also sorry for the name of the topic, I didn’t know how to describe it.

If what I have explained doesn’t make sense, just reply and I’ll try to explain it better because I really need help with this. Thanks :slight_smile:

You could probably just simply convert it to a cframe

(lastCFrame * CFrame.new(0,0,2)).Position

Note the * not +

Cframe multiplication applies the second cframe relative to the first always

:WalkToPart doesn’t work with CFrames, only Vector3s

I apologize, I edited the code to be converted to a position

Do you mean the code you just sent above my last reply?

Yes, it should use the cframe math applied locally then extract just the position which is now relative to the last dummy

The same problem still seems to be occuring. I thought that would work :thinking:

How are you currently getting the lastCFrame?
It should be the humanoidrootpart CFrame or some other reliable center point like that

1 Like

Oh wait, nevermind it is working, just had to change the 2 from the Z to X co-ordinate.

1 Like