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

Help with SetPrimaryPartCFrame in a model?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

The script is:

01local part = script.Parent
02local model = workspace.YOOHOO
03 
04 
05function nicshere(onClick)
06    workspace.THISNIGZ.CanCollide = false
07    model:SetPrimaryPartCFrame(-14, -8.5, -129.5)
08    wait(.1)
09    model:SetPrimaryPartCFrame(-14, -8, -129.5)
10    wait(.1)
11    model:SetPrimaryPartCFrame(-14, -7.5, -129.5)
12    wait(.1)
13    model:SetPrimaryPartCFrame(-14, -7, -129.5)
14    wait(.1)
15    model:SetPrimaryPartCFrame(-14, -6.5, -129.5)
View all 48 lines...

Before I set the script to model:Set.. it was model.Set... and I got an output error of "expected model: calling member function" and now I'm getting "Unable to cast double to CoordinateFrame"

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

"Cast" means "convert". A "double" is a (double-precision) number.

The error is saying that it wanted a CFrame, but got a number.

You have to make a new CFrame, and then provide that, instead of just giving numbers:

1model:SetPrimaryPartCFrame(CFrame.new(-14, -0, -129.5))

but wait -- before you go and change that for every line -- use a loop!

There's a principle of programming called don't repeat yourself. Notice how your code is the same thing over and over? That's a bad thing. You can save yourself a lot of work and allow you to do more by eliminating repetition.

A for loop is designed exactly for this. The only thing that is changing is going from -8.5 to 0 by 0.5. It's really easy to write that into a for loop.

1for y = -8.5, 0, 0.5 do
2 
3end

Read this as for each y from -8.5 to 0 by steps of 0.5 ....

1for y = -8.5, 0, 0.5 do
2    model:SetPrimaryPartCFrame(CFrame.new(-14, y, -129.5))
3    -- notice how I use "y" in the CFrame
4    wait(.1)
5end
0
And How do you break that loop? Arhub06 0 — 7y
0
As normal? With an appropriately guarded break statement. BlueTaslem 18071 — 7y
Ad

Answer this question