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

CFrame, worked then not working?

Asked by
korj5 0
9 years ago
while true do
for i,v in pairs(script.Parent:GetChildren()) do
v.CFrame = v.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/25)
wait()
end
end

the Error is 11:55:06.603 - CFrame is not a valid member of Script 11:55:06.604 - Script 'Workspace.Wall.spin', Line 3 11:55:06.605 - Stack End

http://prntscr.com/9mhy2a

3 answers

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

What your asking you script to do is go through all the children in the model Wall and set the CFrame of each child. But because you put the script into the model, it also tries to set the CFrame of the script, which is not a valid member (a la the error you got).

To fix this we can use the method of Instance :IsA() to check to see what the current child you're looking at is, and if it is a part, then set the CFrame.

while true do
    for _, child in next, script.Parent:GetChildren() do
        if child:IsA("BasePart") then
            child.CFrame = child.CFrame*CFrame.Angles(0, 0, math.pi/25)
        end
    end
    wait()
end
0
Now it's even slow to rotate.. Anyway, thank you for helping me. korj5 0 — 9y
0
Move that wait outside the for loop and they should all rotate at once, sorry about that BlackJPI 2658 — 9y
Ad
Log in to vote
0
Answered by
Tedfat 10
9 years ago

It's trying to "rotate" your script as well. What you want to do is to make it so it excludes your script and only tries to change the cframes of the parts.

Log in to vote
0
Answered by 9 years ago

Ah, the issue is quite simple, here's an explanation:

The error: The CFrame property is only for parts, and basically what the script has tried to do is edit the CFrame property on a script which it doesn't have.

The fix: In order to ensure that the script doesn't attempt to change the CFrame of something which hasn't got a CFrame property, you should do something along the lines of this:

while true do
    for i,v in pairs(script.Parent:GetChildren()) do
        if v:IsA("BasePart") then
            v.CFrame = v.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/25)
            wait()
        end
    end
end

What I've added in your script is the following line: if v:IsA("BasePart") then ... end. What this does is check if it is a Part, Wedge, Union, Cylinder, Sphere etc. and if it is, applies the CFrame value. This would prevent the script from breaking, as this filters out what is a part, and what isn't.

The :IsA("") basically asks: Is this a Part?, Is this a Script?, Is this a SpotLight? and things of the sort, so you are able to filter parts out.

I hope this explanation has helped, please do leave a comment if you require further assistance!

Answer this question