Still have questions? Join our Discord server and get real time help.
1

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

Edited 3 months ago

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 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.

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. mikey2019d 38 — 3mo
0
put [Solved] in the title Spiritlotus 151 — 3mo
0
Nevermind I am still getting the same error )= mikey2019d 38 — 3mo
0
Nvm Solved it sorry for the confusion mikey2019d 38 — 3mo