Moving a cloned model relative to the humanoidrootpart?

What would I use to move a model which is cloned 10 studs infront of the humanoidrootpart? This is what I tried.

script.Parent.MouseButton1Click:Connect(function()
	
	local thatgreencar = game.ReplicatedStorage.GreenSUV
	local player = game.Players.LocalPlayer
	local character = game.Players.LocalPlayer.Character
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	local thatgreencarClone = thatgreencar:Clone()
	
	
	thatgreencarClone.Parent = workspace 
	thatgreencarClone:SetPrimaryPartCFrame(humanoidRootPart.Position)

	
end)

You need to make a CFrame that is 10 studs in front of the player. A way to do this is by multiplying the lookVector, which will move it in the direction that the brick is facing. This will work if the brick is facing the same direction as the player.

thatgreencarClone.CFrame = thatgreencarClone.CFrame + thatgreencarClone.CFrame.lookVector * 10

Look at this article for more details on CFrame math operations, this will definitely help:
CFrame Math Operations (roblox.com)

how do i use this script when its a model with a primarypart?

There is a function called Model:SetPrimaryPartCFrame. It can be used to set the CFrame of the primary part, and all other parts in the model will move with the primary part. I think you could do it like this:

thatgreenCarClone:SetPrimaryPartCFrame(thatgreencarClone.CFrame + thatgreencarClone.CFrame.lookVector * 10)

I might be incorrect somehow in the usage/syntax, so see this article for more details.
Model:SetPrimaryPartCFrame (roblox.com)

You could also use CFrame:ToWorldSpace() to put it 10 studs in front of the player no matter their direction.

1 Like