How to change the position of a model

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hello fellow developers. Recently I have been working on a bathroom sink. The handle of this sink is a model comprised of two parts to make it looks better and not as blocky. I’m trying to script it so that when it is clicked, water comes on and the handle moves up, and when you click it again the handle goes back down and the water comes off.
    This is what I want it to look like when its off:

and this is what I want it to look like when its on:

  1. What is the issue? Include screenshots / videos if possi!
    The issue is that while there is a position property for a single part, there doesn’t appear to be a property like that for a model.
  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked at other posts like this on DevForum but none of them have applied to my situation and I haven’t found any answers to my question.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    I really would like to know what property, if any, of a model does the same thing as the position property for a single part. If there is not a property like this, please explain what I could do. Any help would be greatly appreciated as I could not find any answer on Google or anywhere else. Thank you so much for your time and help, developers.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

To move a Model, you have to define the PrimaryPart in the Model properties, then move that in your codebase.

1 Like

There’s many different ways to solve your problem, but I will answer this directly.

Set the PrimaryPart of the model to one of the parts and then use Model:SetPrimaryPartCFrame(), which essentially moves that part, and then moves every other part in the same relative manner. In this case, use the CFrame of your handle.
https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame

1 Like

So does the PrimaryPart in a model have a Position property?

1 Like

Is there a way to script it without CFrames?

2 Likes

No. As r_aidmaster mentioned, you will need to call on model:SetPrimaryPartCFrame(CFrame here);.

There are other ways to do it with scripts, but they all require CFrame and are even lengthier. Make sure the PrimaryPart is set (in Properties → PrimaryPart). More on that here.

EDIT: my apologies, I did not read the entire question. Using an AnimationController, you can rig and animate any model without giving it a humanoid.

You can either do that or set the model’s CFrame with the method listed above.

1 Like

Alright I haven’t learned about CFrames yet because they seem really complicated but if that’s the only way to solve my problem I’ll learn about them. Thank you for your help.

1 Like

I’ve corrected a mistake I made. Please check my answer now.

1 Like

I think it would be easier for me to learn and use CFrames for this but thank you for clarifying that there is another solution to my problem. If all else fails, I will try to animate it.

1 Like

You don’t per-say need to learn CFrames in order to solve this. If there is too much complexity in the math solution for you, you can always engineer ways around it by thinking outside of the box.

Remember that a CFrame is just a position and orientation of a part, which every part has inside of your game. When you moved the handle up and down for your screenshots, those were actually two distinct CFrame positions.

If you are simply moving one part, a very simple (though, admittedly jank) solution would be to simply have one part be transparent, and when the sink is activated/deactivated, swap which part is transparent and which part is not transparent. Related to this, you could have a sink handle that just provides a CFrame location for when the sink is active, which is removed after you acquire the CFrame of that secondary reference handle.

Of course, you should always strive to perform the best solution possible to a given problem (so not the above). However, that can often take too much effort, and in the real world, good enough is a valid answer. Happy coding! :slightly_smiling_face:

1 Like