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

Why does the error tell me i would attempt to index nil with 'Parent'?

I am trying to make a script that has a camera in the world and copys/removes the folder in the viewportframe but it keeps on erroring if it tries to change the parent of a cloned part

Players.EnderPowerHD.PlayerGui.SurfaceGui.LocalScript:20: attempt to index nil with 'Parent'

/\ The Error

/ My Local Script

game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)

local camera = Instance.new("Camera")
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Cam.CFrame
script.Parent.ViewportFrame.CurrentCamera = camera

while true do
	script.Parent.ViewportFrame.Folder:Destroy()
	local folder = Instance.new("Folder")
	folder.Parent = script.Parent.ViewportFrame
	
	local world = game.Workspace:GetChildren()
	
	for i = 1,#world do
		if world[i]:IsA("Terrain") == false then
			if world[i]:IsA("Camera") == false then
				if world[i] ~= nil then
					local part = world[i]:Clone()
					part.Parent = folder
				end
			end
		end
	end
	
	wait(1)
	
end

2 answers

Why are you doing a for loop on this?

 for i = 1,#world do
	        if world[i]:IsA("Terrain") == false then
	            if world[i]:IsA("Camera") == false then
	                if world[i] ~= nil then
	                    local part = world[i]:Clone()
	                    part.Parent = folder
                end
            end
	        end
	    end

Here a fixed line of your code

for i, Object in pairs(world) do
	if Object.ClassName ~= "Terrain" and Object.ClassName ~= "Camera" then
		if Object ~= nil then
			local Cloned = Object:Clone()
			Cloned.Parent = folder
		end
	end
end

3 comments

0

These 2 are the exact same just that i used an for loop (It gives the same error even with the part of the codes exchanged)

0

Im testing that out, why do you have a surface gui on the players gui?

0

you have to have it in the player guit or else you cant see it you can only adornee it to a part

Found the problem myselfe i was copying Player Models which are not Archivable i had to turn Archivable on before i copy them

1 comment

0

Mark the post as solved otherwise people will continue to click on this and now realize that it's solved.

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