Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Move model PrimaryPart y position only?

Asked by 6 years ago
Edited 6 years ago

What am I doing wrong here? The commented line is what I was trying to do as it would move the whole model. However, I get an error that says "Unable to cast double to CoordinateFrame"

What this is supposed to do is if the y position is greater then 20 then it will bring the model down to a y of 10

local PrimaryPart = script.Parent.PrimaryPart
local Model = script.Parent

while true do
    wait()
    if PrimaryPart.Position.Y > 20 then
        PrimaryPart.Position = Vector3.new(PrimaryPart.Position.X, 10, PrimaryPart.Position.Z) -- Doesn't move the whole model
        --Model:SetPrimaryPartCFrame(PrimaryPart.Position.X, 10, PrimaryPart.Position.Z)
    end
end

1 answer

Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
6 years ago

You did everything right, you just forgot a few things. If you want to use a Vector3 to move the entire model, use:

model:MoveTo(Vector3.new(0,0,0))

If you want to position the model using a CFrame, you did it right except you're trying to make the CFrame out of 3 numbers, when you should be making it out of a Vector3. Just change it so there's a Vector3.new() around the 3 numbers inside the CFrame.new for your model:SetPrimaryPartCFrame

0
Well the problem with doing model:SetPrimaryPartCFrame(Vector3.new(0,0,0) ) is you will get a error of "Unable to cast Vector3 to CoordinateFrame" YouSNICKER 131 — 6y
0
Oops, I see what you mean. Thanks man! I didn't think of using the MoveTo function. YouSNICKER 131 — 6y
0
Also, that's why I said you put the Vector3.new() INSIDE the CFrame.new(). Eqicness 255 — 6y
Ad

Answer this question