Ok so, I'm creating a Real Time Strategy game where I need units to be moved to a specific point. I've created a part called MoveCommand that when I click on the base plate it moves where ever the mouse.target is. So I want the Unit (that is going to be made out of bricks) to move to the MoveCommand location and it needs to update whenever the MoveCommand moves to a new location (I don't want it to move once and never move again). I don't want the Unit to teleport so I'd like it to move like below if possible
So the code below makes the unit move how I'd like it to and sets the speed ect..
for i = 1 , 500 do workspace.Grunt.Head.CFrame = workspace.Grunt.Head.CFrame + Vector3.new(0,0,.03) wait (.03) end
(Head is a normal brick)
I've tried changing the Vector3 coordinates to a specific part position like this...
for i = 1,500 do workspace.Grunt.Head.CFrame = workspace.Grunt.Head.CFrame + Vector3.new(workspace.MoveCommand.Position) wait (.03) end
The part wont budge its unanchored and I tried adding a humanoid to it so I could get it to move but it still didn't.
Any help would be Appreciated Thank You!
Pretty easy, First get the players and then the mouse:
local player = game.Players.LocalPlayer --Get the player local mouse = player:GetMouse() --Get the mouse mouse.Button1Down:connect(function() --Funtion for i,v in pairs (game.Workspace.Units:GetChildren()) do --Get the brick you trying to move if v:IsA ("Model") then --Use the IsA method v.Humanoid:MoveTo((mouse.Hit).p)--Brick needs to have a humanoid inside end end end)
If this helped remenber to accept my answer!
If you are moving a model use MoveTo(). Note that MoveTo() will move all the parts in a model relative to the PrimaryPart(Meaning you want to figure out what position of the primary part will work for the entire model). If you don't know what the primary part is or haven't set it, its a property under model. If you are just trying to move a part, it should error in the output if the move was unsuccessful. Unanchoring the part will not affect moving the CFrame(an anchored part will move just fine). I could not find any errors in your code above and I ask that you edit it and add code blocks so its easier to read.
game.ModelName:MoveTo(Vector 3 Position) --moves all the parts in a model relative to the Primary Part position given in Vector3