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

attempt to index nil with 'HPIBlitz'?

I'm trying to make an RC car, but the camera doesn't work. I get the error attempt to index nil with 'HPIBlitz'. What does this mean? How do I fix it? Localscript:

Camera = game.Workspace.CurrentCamera
LocPlayer = game.Players.LocalPlayer
for _, v in pairs(workspace:GetDescendants()) do
	if v.Name == LocPlayer.Character.Name .. "'s car" then
		Object = v
	end
end
Vehicle = Object.HPIBlitz.Shell
Player = script.Parent.Humanoid
Camera.CameraSubject = Vehicle
Camera.CameraType=3
if Player.Sit == false then
	Camera.CameraSubject = Player
	Camera.CameraType = Enum.CameraType.Custom
	script:Destroy()
end
--This is parented to the server script.

Server script:

print("Camera script loading")

script.Parent.ChildAdded:Connect(function(weld)
	if weld.Name == "SeatWeld" then
		local h = script.Parent.Occupant
		wait()
		if h.Sit == true then
			local newscript = script.CameraChange:Clone()
			newscript.Parent = h.Parent	
		end  
	end
end)

Change name of the model:

local seat = script.Parent.rrccccc
seat.ChildAdded:Connect(function(weld)
	if weld.Name == "SeatWeld" then
		local h = seat.Occupant
		wait()
		if h.Sit == true then
			script.Parent.Name = h.Parent.Name .. "'s car"	
		end  
	end
end)
--Server script

Remove name of the model:

local seat = script.Parent.rrccccc
seat.ChildRemoved:Connect(function(weld)
	script.Parent.Name = "HPIBlitz" 
end)
--Server script

1 answer

Try this maybe:

if workspace:FindFirstChild(LocPlayer.Character.Name .. "'s car") then
	Object = LocPlayer.Character.Name .. "'s car"
end
-- for lines 3 - 7 on 1st script

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