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

Attempt to index nil with 'CFrame' ?

Asked by 3 years ago

Hello. I made a script that moves the whole model when you click it using it's PrimaryPart CFrame. But for some reason, I got "Attempt to index nil with 'CFrame' " error in the output. What's the source of error that I get?

function onClick()
    script.Parent.ClickDetector.MaxActivationDistance=0
    for i = 1,20 do
        script.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.PrimaryPart.CFrame + CFrame.new(Vector3.new(0,.10,0)))
        wait()
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I don't think you are supposed to add CFrame to another CFrame. Instead,multiply:

script.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.PrimaryPart.CFrame * CFrame.new(Vector3.new(0,.10,0)))

Hope this helps!

0
Thank you so much, that kinda helped but it actually wasn't a sollution for my issue, It gave me the same error. Actually, it was my bad. I just realized line 4 was actually wrong. I added the model name after .Parent property "ExitDoor" which is supposed to move (script.Parent.Parent.Parent.ExitDoor.PrimaryPart.CFrame). I'll still accept that as a sollution, thank you so much. Va1t_Dev 86 — 3y
Ad

Answer this question