The script is:
01 | local part = script.Parent |
02 | local model = workspace.YOOHOO |
03 |
04 |
05 | function 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 ) |
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"
"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:
1 | model: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.
1 | for y = - 8.5 , 0 , 0.5 do |
2 |
3 | end |
Read this as for each y
from -8.5
to 0
by steps of 0.5
....
1 | for 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 ) |
5 | end |