Attempt to index nil with 'CFrame'

18:16:48.379 Players.AxeI_c.PlayerGui.CamerasRocket.Frame.LocalScript:21: attempt to index nil with ‘CFrame’ - Client - LocalScript:21
18:16:48.380 Stack Begin - Studio
18:16:48.380 Script ‘Players.AxeI_c.PlayerGui.CamerasRocket.Frame.LocalScript’, Line 21 - Studio - LocalScript:21
18:16:48.380 Stack End - Studio

Script:

local Seat =  script.Parent -- Path to seat
local lastplayer = 0

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
	local CameraOne = script.Parent.Parent.CameraRocket1:GetFullName()
	local CameraTwo = script.Parent.Parent.CameraRocket2:GetFullName()
	local Char = Seat.Occupant.Parent
	local player = game.Players:GetPlayerFromCharacter(Char)
	lastplayer = game.Players:GetPlayerFromCharacter(Char)
	game.ReplicatedStorage.EnableCameraGui:FireClient(player)
	game.ReplicatedStorage.Seat1:FireClient(player, CameraOne, CameraTwo)
	
elseif Seat.Occupant == nil then
	game.ReplicatedStorage.DisableCameraGui:FireClient(lastplayer)
end
end)

LocalScript:

local Camera1 = ""

local Camera2 = ""

local CurrentCamera = workspace.CurrentCamera

game.ReplicatedStorage.Seat1.OnClientEvent:Connect(function(player, CameraOne, CameraTwo)

Camera1 = CameraOne

Camera2 = CameraTwo

end)

script.Parent.Camera1Button.MouseButton1Click:Connect(function()

CurrentCamera.CFrame = Camera1.CFrame

end)

script.Parent.Camera2Button.MouseButton1Click:Connect(function()

CurrentCamera.CFrame = Camera2.CFrame

end)

You are setting the camera variables to strings. If you want the CFrame, you will need to return the instances.

What are you trying to do here? Camera1 is a string value so there is no CFrame property. You first set Camera1/2 as an empty string, and then later fill it with script.Parent.Parent.CameraRocket1:GetFullName(), but :GetFullName() returns yet another string instance.

Also, onClientEvent doesn’t need the first player argument as you can get the player with game.Players.LocalPlayer

3 Likes