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

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

Asked by 2 years ago

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)
1
The issue is that the 'part' variable is nil. You can't index a nil value, thus, why you are getting an error. appxritixn 2235 — 2y
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 JustinWe12 723 — 2y

1 answer

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago

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

Answer this question