Constantly changing a models position?

local Mouse = game.Players.LocalPlayer:GetMouse()

local button1 = script.Parent:WaitForChild('Model1')

button1.Activated:Connect(function()
	local clone = button1:FindFirstChild('Model'):Clone()
	while wait() do				
		if Mouse.Target then
			if Mouse.Target.Name == "Base" then
				
				clone:MoveTo(Vector3.new(Mouse.Hit))
				clone.Parent = workspace.CurrentCamera

			end
		end
	end
end)

I’m trying to make a placement system, so that when the player clicks a button, it sets a model into their camera and is suppose to follow the players mouse until they click (to place it down) however atm when I click the button it just spawns ontop of my characters head and it doesn’t move positions.

3 Likes

You don’t use MoveTo for this, use Vector3,CFrame and SetPrimaryPartCFrame.

Did that, which it now follows the mouse, but the part is tilted

The transparent part is the PrimaryPart, and it should be in line with the baseplate

Try rotate the primary part then


New problem :sweat_smile: the rocks aren’t in their correct part, and as I move the part around they also move in random and odd rotations and positions

Just as a side note: don’t use a while loop, just listen to the mouse’s Move event.

Mouse.Move:Connect(function()

If you did this, if the player moved or camera angle changed it wouldn’t update until you actually moved your mouse.

Good point, actually. Haven’t thought about that lol.

Yep, it’s something you don’t really think about. I only thought of it because I ran into this “problem” awhile ago.

1 Like

Learning from experience is the best learning!

1 Like

Erk - I feel like I’m repeating myself now, but just to be sure, please don’t use SetPrimaryPartCFrame for repeated uses like mouse movements or animating.

As for a more in-depth reply as to why, and what other solutions exists, I have this: How do you use CFrame for the children of a model - #8 by As8D

That’s just for the “move a model” subproblem of OP’s issue - but yeah, make sure the root/primary part is following a standard.

2 Likes

Useful resource, thank you for sharing! I’ll make sure to utiliize this and I hope the OP can aswell!