Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index nil with 'CFrame' ?

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

✓ Accepted answer

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!

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.