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
Never mind I found the problem to be I am calling the variable after I changed the parent so it gives a nil value.
put [Solved] in the title
Nevermind I am still getting the same error )=
Nvm Solved it sorry for the confusion