How to move an model

how do you actually move a model because there is no property of CFrame or Position in it would an answer be like moving the parts or objects inside the model to a certain point?

1 Like

You should address here.

Model:SetPrimaryPartCFrame(TheTargetCFrame) should work.

3 Likes

great but how about tweening them to another position

You would tween the primary part I think. (not sure)

Just make a loop that lerps the CFrame.

You would use Model:MoveTo() for that. You may read about it here.

I dont think it works like that, animating only the Primary Part wont work. Only Model:SetPrimaryPartCFrame() moves the entire model.

What is my best suggestion is to make an hitbox then anchor it,disable the can collide and make it transparent,use that hitbox as a primary part CFrame and use Model:SetPrimaryPartCFrame(CFrame.new()). You could use :MoveTo() method. Or you could get the descendant of the model and loop through them (if you want to use tween)

1 Like

I found a tutorial on how to do it.

Id prefer SetPrimaryPartCFrame(), though if youre just gonna move the positions then :MoveTo() is the answer for you.

Then, that tutorial should be the answer for OP’s question.

SetPrimaryPartCFrame is used for moving models. If you find it hard to use it, another not so good way to do is to loop all the parts inside the model to a position or CFrame.

You can also set the main part of the model as the primary part of the model and weld all the other parts to the primary part and just set the position/CFrame of the primary part.

here is an problem if i dont add a break it doesnt work and if i even added it it wont work neither here is the piece of code

game.ReplicatedStorage.Events.MultipleSwords.OnServerEvent:Connect(function(player, Pos)
	if not MultipleSwordsDebounce then
		local function SpawnSwords(Swords, Character)
			local ClonedSwords = Swords:Clone()
			ClonedSwords.Parent = Character.Head
			ClonedSwords:MoveTo(Character.Head.Position + Vector3.new(3,6,0))
		end
		
		local function MoveSwords(Swords, Character)
			local Swords = Character.Head.Swords
			
			for _, AllSwords in pairs(Swords:GetChildren()) do
				local Tweeninfo = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
				
				local TweenStuff = TweenService:Create(AllSwords, Tweeninfo, {
					Position = Pos
				})
				
				TweenStuff:Play()
				TweenStuff.Completed:Wait()
				
				AllSwords:Destroy()
				
				Character.Humanoid.WalkSpeed = 16
			end
		end
		
		local flying = false
		
		local function Fly(Character)
			flying = true
			
			local myHRP = Character:WaitForChild("HumanoidRootPart")
			local camera = game.Workspace.CurrentCamera
			
			local flying = false
			local speed = 0.5
			
			
			local bp = Instance.new("BodyPosition", myHRP)
			bp.MaxForce = Vector3.new()
			bp.D = 10
			bp.P = 10000
			
			local bg = Instance.new("BodyGyro", myHRP)
			bg.MaxTorque = Vector3.new()
			bg.D = 10
			
			while flying do
				RunService.Stepped:wait()
				bp.Position = myHRP.Position +((myHRP.Position - camera.CFrame.p).unit * speed)
				bg.CFrame = CFrame.new(camera.CFrame.p, myHRP.Position)
			end
		end
		
		local function EndFly(Character)
			local bp = Character.HumanoidRootPart.BodyPosition
			local bg = Character.HumanoidRootPart.BodyGyro
			
			bp.MaxForce = Vector3.new()
			bg.MaxTorque = Vector3.new()
			flying = false
		end
		
		MultipleSwordsDebounce = true
		
		local Swords = game.ReplicatedStorage.GameObjects.Swords
		
		local Character = player.Character
		local Humanoid = Character.Humanoid
		local Anim = Humanoid:LoadAnimation(Character.AnimationTracks.MultiSwords)
		
		-- Fly(Character)
		Anim:Play()
		Humanoid.WalkSpeed = 0
		SpawnSwords(Swords, Character)
		
		Anim.Stopped:wait()
		-- play anim
		MoveSwords(Swords, Character)
		-- EndFly(Character)
		MultipleSwordsDebounce = false
	end
end)

As you’ve localised the functions I believe that the two functions run with independent values of flying, if you remove ‘local function’ and replace it with ‘function’ this should reflect the behaviour you wanted.

When moving a model you can either use :MoveTo() which will move the model to the best spot, so if a model can’t fit in the space it will place it above it or :SetPrimaryPartCFrame() which will move the model to the CFrame irregardless of whether it will fit.

To move it smoothly, weld all parts to a primary part and then tween said primary part: the player’s primary part for example is the humanoid root part.

Hopefully this should solve all your problems / questions you’ve been having.

can you give me an example of the primary part i don’t know how and how to make it and position it correctly

fixed all of the problems i now need to figure out why it only moves 1 sword and not the others

any idea why? if you need the code it is here

function MoveSwords(Swords, Character, Pos)
	local Swords = Character.Head.Swords
	for _, AllSwords in pairs(Swords:GetChildren()) do
		local Tweeninfo = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		
		local TweenStuff = TweenService:Create(AllSwords, Tweeninfo, {
			Position = Pos
		})
		
		TweenStuff:Play()
		TweenStuff.Completed:Wait()
		
		MultiSwordEvent = AllSwords.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChildOfClass("Humanoid") then
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				
				if player then
					local character = player.Character
					
					if character then
						local Humanoid = character.Humanoid
						
						if Humanoid then
							Humanoid:TakeDamage(30)
						end
					end
				end
			end
		end)
		
		AllSwords.Parent:Destroy()
		Character.Humanoid.WalkSpeed = 16
		
		pcall(function()
			MultiSwordEvent:Disconnect()
			MultiSwordEvent = nil
			MultipleSwordsDebounce = false
		end)
		break
	end
end

Well if you have a ‘break’ at the end, you essentially break the loop of all the swords hence it wont work.

A primary part is just a part which you specify - its not an actual thing. Any part can be a primary part in a model (and under a model’s property you can set said part to make things easier as well as allowing for parts to have specific names on top of this) - just as long as all parts are welded to that central part they’ll move as if they are one.

ok that solves all stuff but when i notice that the part moves it moves at one point but i wanted it to have each pos different from each other

Please never use SetPrimaryPartCFrame unless you aren’t going to be calling it often. It tears models apart slowly and if accuracy is something you value, it will go down overtime and you will see visible drifts. It takes a few hundred calls before it gets there, but you can fast travel there with tweening.

changeno linked a tutorial I wrote on tweening models which you should check out. It’s some posts up.

3 Likes