Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago
Edited 3 years 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 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.

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

1 answer

Log in to vote
0
Answered by 3 years ago

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

Ad

Answer this question