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:

local part = script.Parent
local model = workspace.YOOHOO


function nicshere(onClick)
    workspace.THISNIGZ.CanCollide = false
    model:SetPrimaryPartCFrame(-14, -8.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -8, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -7.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -7, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -6.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -6, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -5.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -4.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -4, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -3.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -3, -129.5)
    wait(.1)
    workspace.THISNIGZ.Transparency = 1
    model:SetPrimaryPartCFrame(-14, -2.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -2, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -1.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -1, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -.5, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, -0, -129.5)
    wait(.1)
    model:SetPrimaryPartCFrame(-14, 0.1, -129.5)

end

script.Parent.ClickDetector.MouseClick:connect(nicshere)

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:

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.

for y = -8.5, 0, 0.5 do

end

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

for y = -8.5, 0, 0.5 do
    model:SetPrimaryPartCFrame(CFrame.new(-14, y, -129.5))
    -- notice how I use "y" in the CFrame
    wait(.1)
end
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