Move model to mouse.hit.position when I click a tool

Using the following code, I wanted to move a Model I placed in ReplicatedStorage to mouse.Hit.Position when I click.

However, it doesn’t move the model and only places it into workspace

image

image

This is the layout in the Tool:
image

I have tried :MoveTo(), :PivotTo() :SetPrimaryPartCFrame().
I have also moved the original model into ServerStorage and that didn’t change anything either

Am I just formatting it wrong or is this not possible with models?

Does the model have a primary part? That’s all I see that could be the issue at first glance.
edit:
actually I see the script also destroys its own parent before doing the last line, which I think would also stop the script early.

you are doing Vector3.new(Hit.Position) which will error since Hit.Position is already a Vector3.

You are also destroying the tool before the thing is moved which means the script stops running before the object is moved

So far still no fix, I have altered the code to the following and i’m also giving video footage on whats happening.

I do have a PrimaryPart set on the model.

new server script:
image

(I also tried just “hit” instead of hit.Position)

Video:

P.S. I also just tried looping through all objects in the model and moving them to hit/hit.position. No success there either.

so far in the new server-script, I have never seen model:MoveTo(). if you’re trying to set the position of a model, you should be using :PivotTo(). However, you need to get the CFrame for using this, but mouse.Hit is already a CFrame, so the line would look something like this

repMDL:PivotTo(hit)

if it doesn’t work, let me know

1 Like

I’ve tried that with the same outcome, also tried SetPrimaryPartCFrame and looping through each object individually.

could you send me your code? it should work. maybe you don’t have a PrimaryPart on the model. check to see if that’s the case.

also, are there any errors?

1 Like

In the output it says “Unable to cast Instance to CoordinateFrame”.

image

image

Does PrimaryPart support meshparts?

1 Like

PrimaryPart should work for any BasePart (a physical object, like a union or part for “instance” haha). could you send me the new code? I tested it in studio and it worked flawlessly.

WAIT, I just noticed that in the LocalScript, you shouldn’t put “plr” as the first argument. you do not need it because it’s already passed onto the next script automatically.

example LocalScript:

remote:FireServer(mouse.Hit)

example ServerScript

remote.OnServerEvent:Connect(function(plr, hit)

end)

THANK YOU! this was the issue. It’s always the tiny details

1 Like