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