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

Why am i getting attempted to index nil with parent?[SOLVED]

I keep getting this error when I click a button any more than 4 times. here is my code

local List = game.Players.LocalPlayer.PlayerGui.MainMenu.Screens.ShopFrame.GunNames.GunNames2.Lists:GetChildren()
local SelectedClass = game.Players.LocalPlayer.PlayerGui.MainMenu.Screens.ShopFrame.GunNames.CurrentClassSelected
local ViewPort = script.Parent
local cam = workspace.CurrentCamera
cam.CameraType = "Fixed"
for int1 = 1,#List,1 do
	local ClassGunContainers = List[int1]:GetChildren()
	for int2 = 1,#ClassGunContainers,1 do
		local GunNamesByClass = ClassGunContainers[int2]:GetChildren()
		for int3 = 1,#GunNamesByClass,1 do
			GunNamesByClass[int3].MouseButton1Click:Connect(function()
				local WeaponsAndTools = workspace.WeaponsAndTools
				local SelectedWeapon = WeaponsAndTools:FindFirstChild(tostring(GunNamesByClass[int3]))
				SelectedWeapon.Parent = ViewPort
				print(SelectedWeapon.Parent)
			end)
		end	
	end
end
  

The error is: Players.mikey2019d.PlayerGui.MainMenu.Screens.ShopFrame.ViewportFrame.ViewPortScript:14: attempt to index nil with 'Parent'

Thanks for taking time to read this. I apologize if it is a very simple mistake. Thanks.

4 comments

0

Never mind I found the problem to be I am calling the variable after I changed the parent so it gives a nil value.

0

put [Solved] in the title

0

Nevermind I am still getting the same error )=

0

Nvm Solved it sorry for the confusion

1 answer

The most likely case your getting a nil value is probably that something doesn't exist.

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