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)
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!