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

I have probleme with this script. Can you help me ? attempt to index nil with 'CFrame'

Hi have problem with this script.

local part = PART

game:GetService('RunService').RenderStepped:connect(function()
game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(game.Workspace.CurrentCamera.CoordinateFrame.p, part.CFrame.p)
end)

2 comments

1

The issue is that the 'part' variable is nil. You can't index a nil value, thus, why you are getting an error.

0

phxntxsmic is right. You need to say where the part is relative to the game or script or something. For example, game.Workspace.Part or script.Parent

1 answer

✓ Accepted answer

Like phxntxsmic said, you have to reference the part variable to the parent. And remember that this has to be in a Localscript, since renderstepped only works in the client.

##Script

local part = workspace.Part

game:GetService('RunService').RenderStepped:connect(function()
	game.Workspace.CurrentCamera.CoordinateFrame = CFrame.new(game.Workspace.CurrentCamera.CoordinateFrame.p, part.CFrame.p)
end)

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