Attempt to call a nil value

it says it attempted to call a nil value when i try to run the function, doesn’t say anything in the script, only in client dev console.

function setupButtons()
	for i, v in pairs(script.Parent.Skins:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "knife")
			end)
		end
	end
	for i, v in pairs(script.Parent.Abils:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "ability")
			end)
		end
	end
	for i, v in pairs(script.Parent.Gears:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "gear")
			end)
		end	
	end
		for i, v in pairs(script.Parent.RevolverSkins:GetChildren()) do
			if v:IsA("TextButton") then
				v.Activated:connect(function()
					displayItem(v.Name, "revolver")
				end)
			end
		end
	end
	end

setupButtons()
2 Likes

What line does the error lie in?

Try using :FindFirstChild() to make sure the objects you’re calling in are actually there. Sometimes this will fix a nil problem.

Trying it now, hopefully it works

still a nil value. line 415 is the error

the code error is at line 415 .

Hm, could you try adding print statements? It might also be because of the Activated function through the loop?

1 Like

The prints didn’t go through, so the function doesn’t even succeed in running.

Strange, maybe it’s cause of the stuff you’re looping through?

im not sure :confused: im having brain dead

1 Like

Which line in your script is line 415?

the start of the function itself

Can you provide some more context of where exactly your error is occurring?

Is the full stack trace available?

local player = game.Players.LocalPlayer
local repStore = game:GetService("ReplicatedStorage")
local skins = player:WaitForChild("Knife")
local revolverskins = player:WaitForChild("Revolver")
local abils = player:WaitForChild("Ability")
local gears = player:WaitForChild("Gear")
local plrCredits = player:WaitForChild("Credits")
local shopevnt = repStore:WaitForChild("shopEvent")

local e_Knife = player:WaitForChild("CurrentKnife")
local e_Revolver = player:WaitForChild("CurrentRevolver")
local e_Abil = player:WaitForChild("CurrentAbility")
local e_Gear = player:WaitForChild("CurrentGear")

local storeLIB = repStore:WaitForChild("shopLIB")

local winCAM = workspace.CurrentCamera:Clone()
winCAM.Parent = game.Workspace
winCAM.Name = "shopView"

local dispMain = script.Parent.displayMAIN
local window = dispMain.window
window.CurrentCamera = winCAM
local buyButton = dispMain.Buy
local equipButton = dispMain.Equip
local txt_cost = dispMain.cost
local txt_desc = dispMain.desc
local txt_title = dispMain.title

local knfCFrames = CFrame.new(0,0,-1.3) * CFrame.Angles(0,math.rad(-90),0) * CFrame.Angles(math.rad(-45),0,0)

local testVP = storeLIB.textures.Knife.object:Clone()
testVP.Parent = window
testVP.CFrame = winCAM.CFrame * knfCFrames

local btnColors = script.Parent.colorz
local btnA = storeLIB.ButtonA

local currentItem = "Identifier"
local currentType = "ability"

function refreshStore()
	script.Parent.Credits.Text = plrCredits.Value
	--skins
	local skz = script.Parent.Skins
	for e, g in pairs(skz:GetChildren()) do
		if g:IsA("UIListLayout") then
			--do nothing
		else
			g:Destroy()
		end
	end
	local gunskinLIB = storeLIB.revolvertextures:GetChildren()
	local skinLIB = storeLIB.textures:GetChildren()
	table.sort(skinLIB,function(a,b)
		return (b.Cost.Value > a.Cost.Value)
	end)
	
	for i, v in pairs(skinLIB) do
		local matched = 0
		for j, knfA in pairs(skins:GetChildren()) do
			if v.Name == knfA.Name then
				matched = 1
				if v.Name == e_Knife.Value then
					matched = 2
				end
			end
		end
		
		table.sort(gunskinLIB,function(a,b)
			return (b.Cost.Value > a.Cost.Value)
		end)
		for i, v in pairs(gunskinLIB) do
			local matched = 0
			for j, gunA in pairs(revolverskins:GetChildren()) do
				if v.Name == gunA.Name then
					matched = 1
					if v.Name == e_Revolver.Value then
						matched = 2
					end
				end
			end
			end
		
		local newBtn = btnA:Clone()
		newBtn.LayoutOrder = i
		newBtn.itemName.Text = v.Name
		newBtn.Parent = skz
		newBtn.Name = v.Name
		
		if matched == 1 then
			newBtn.BackgroundColor3 = btnColors.Owned.Value
		elseif matched == 2 then
			newBtn.BackgroundColor3 = btnColors.Equipped.Value
		else
			newBtn.BackgroundColor3 = btnColors.Unowned.Value
			if v:FindFirstChild("Unlisted") then
				newBtn:Destroy()
			end
			
		end
	end
	--skins
	
	--abils
	local skz = script.Parent.Abils
	for e, g in pairs(skz:GetChildren()) do
		if g:IsA("UIListLayout") then
			--do nothing
		else
			g:Destroy()
		end
	end
		
	local abilLIB = storeLIB.abils:GetChildren()
	table.sort(abilLIB,function(a,b)
		return (b.Cost.Value > a.Cost.Value)
	end)
	
	for i, v in pairs(abilLIB) do
		local matched = 0
		for j, abilA in pairs(abils:GetChildren()) do
			if v.Name == abilA.Name then
				matched = 1
				if v.Name == e_Abil.Value then
					matched = 2
				end
			end
		end
		
		local newBtn = btnA:Clone()
		newBtn.LayoutOrder = i
		newBtn.itemName.Text = v.Name
		newBtn.Parent = skz
		newBtn.Name = v.Name
		
		if matched == 1 then
			newBtn.BackgroundColor3 = btnColors.Owned.Value
		elseif matched == 2 then
			newBtn.BackgroundColor3 = btnColors.Equipped.Value
		else
			newBtn.BackgroundColor3 = btnColors.Unowned.Value
			if v:FindFirstChild("Unlisted") then
				newBtn:Destroy()
			end
			
		end
	end
	--abils
	
	--gears
	local skz = script.Parent.Gears
	for e, g in pairs(skz:GetChildren()) do
		if g:IsA("UIListLayout") then
			--do nothing
		else
			g:Destroy()
		end
	end
	
	local gearLIB = storeLIB.gears:GetChildren()
	table.sort(gearLIB,function(a,b)
		return (b.Cost.Value > a.Cost.Value)
	end)
	
	for i, v in pairs(gearLIB) do
		local matched = 0
		for j, gearA in pairs(gears:GetChildren()) do
			if v.Name == gearA.Name then
				matched = 1
				if v.Name == e_Gear.Value then
					matched = 2
				end
			end
		end
		
		local newBtn = btnA:Clone()
		newBtn.LayoutOrder = i
		newBtn.itemName.Text = v.Name
		newBtn.Parent = skz
		newBtn.Name = v.Name
		
		if matched == 1 then
			newBtn.BackgroundColor3 = btnColors.Owned.Value
		elseif matched == 2 then
			newBtn.BackgroundColor3 = btnColors.Equipped.Value
		else
			newBtn.BackgroundColor3 = btnColors.Unowned.Value
			if v:FindFirstChild("Unlisted") then
				newBtn:Destroy()
			end
			
		end
	end
	--gears
end

function displayItem(itemName, tipo)
	currentItem = itemName
	for i, v in pairs(window:GetChildren()) do
		if v:IsA("UIAspectRatioConstraint") then
			--do nothing
		else
			v:Destroy()
		end
	end
	--wait(0.01)
	if tipo == "knife" then
		currentType = "skin"
		local matched = 0
		for j, knfA in pairs(skins:GetChildren()) do
			if itemName == knfA.Name then
				matched = 1
				if itemName == e_Knife.Value then
					matched = 2
				end
			end
		end
		local datA = storeLIB.textures:FindFirstChild(itemName)
		if datA then
			local newObject = datA.object:Clone()
			newObject.Parent = window
			newObject.CFrame = winCAM.CFrame * knfCFrames
			if datA.Cost.Value <= 0 then
				txt_cost.Text = "Free"
			else
				txt_cost.Text = datA.Cost.Value.."c"
			end
			txt_title.Text = datA.Name
			txt_desc.Text = datA.Desc.Value
			txt_desc.TextSize = txt_title.TextBounds.Y
		end
		if matched == 1 then
			equipButton.Text = "Equip"
			equipButton.Visible = true
			buyButton.Visible = false
		elseif matched == 2 then
			equipButton.Text = "Equipped"
			equipButton.Visible = true
			buyButton.Visible = false
		else
			equipButton.Visible = false
			buyButton.Visible = true
		end
	elseif tipo == "ability" then
		currentType = "ability"
		local matched = 0
		for j, abilA in pairs(abils:GetChildren()) do
			if itemName == abilA.Name then
				matched = 1
				if itemName == e_Abil.Value then
					matched = 2
				end
			end
		end
		local datA = storeLIB.abils:FindFirstChild(itemName)
		if datA then
			local newObject = datA.icon:Clone()
			newObject.Parent = window
			newObject.BackgroundTransparency = 0
			newObject.BorderSizePixel = 0
			newObject.BackgroundColor3 = datA.HUDcolor.Value
			txt_cost.Text = datA.Cost.Value.."c"
			txt_title.Text = datA.Name
			txt_desc.Text = datA.Desc.Value
			txt_desc.TextSize = txt_title.TextBounds.Y
		end
		if matched == 1 then
			equipButton.Text = "Equip"
			equipButton.Visible = true
			buyButton.Visible = false
		elseif matched == 2 then
			equipButton.Text = "Equipped"
			equipButton.Visible = true
			buyButton.Visible = false
		else
			equipButton.Visible = false
			buyButton.Visible = true
		end
	elseif tipo == "gear" then
		currentType = "gear"
		local matched = 0
		for j, gearA in pairs(gears:GetChildren()) do
			if itemName == gearA.Name then
				matched = 1
				if itemName == e_Gear.Value then
					matched = 2
				end
			end
		end
		local datA = storeLIB.gears:FindFirstChild(itemName)
		if datA then
			local newObject = datA.icon:Clone()
			newObject.Parent = window
			txt_cost.Text = datA.Cost.Value.."c"
			txt_title.Text = datA.Name
			txt_desc.Text = datA.Desc.Value
			txt_desc.TextSize = txt_title.TextBounds.Y
		end
		if matched == 1 then
			equipButton.Text = "Equip"
			equipButton.Visible = true
			buyButton.Visible = false
		elseif matched == 2 then
			equipButton.Text = "Equipped"
			equipButton.Visible = true
			buyButton.Visible = false
		else
			equipButton.Visible = false
			buyButton.Visible = true
		end
		if tipo == "revolver" then
			currentType = "revolverskin"
			local matched = 0
			for j, gunA in pairs(revolverskins:GetChildren()) do
				if itemName == gunA.Name then
					matched = 1
					if itemName == e_Revolver.Value then
						matched = 2
					end
				end
			end
			local datA = storeLIB.textures:FindFirstChild(itemName)
			if datA then
				local newObject = datA.object:Clone()
				newObject.Parent = window
				newObject.CFrame = winCAM.CFrame * knfCFrames
				if datA.Cost.Value <= 0 then
					txt_cost.Text = "Free"
				else
					txt_cost.Text = datA.Cost.Value.."c"
				end
				txt_title.Text = datA.Name
				txt_desc.Text = datA.Desc.Value
				txt_desc.TextSize = txt_title.TextBounds.Y
			end
			if matched == 1 then
				equipButton.Text = "Equip"
				equipButton.Visible = true
				buyButton.Visible = false
			elseif matched == 2 then
				equipButton.Text = "Equipped"
				equipButton.Visible = true
				buyButton.Visible = false
			else
				equipButton.Visible = false
				buyButton.Visible = true
			end	
	end
end

refreshStore()

displayItem("Knife", "knife")

function setupButtons()
	for i, v in pairs(script.Parent.Skins:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "knife")
			end)
		end
	end
	for i, v in pairs(script.Parent.Abils:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "ability")
			end)
		end
	end
	for i, v in pairs(script.Parent.Gears:GetChildren()) do
		if v:IsA("TextButton") then
			v.Activated:connect(function()
				displayItem(v.Name, "gear")
			end)
		end	
	end
		for i, v in pairs(script.Parent.RevolverSkins:GetChildren()) do
			if v:IsA("TextButton") then
				v.Activated:connect(function()
					displayItem(v.Name, "revolver")
				end)
			end
		end
	end
	end

setupButtons()

equipButton.Activated:Connect(function()
	shopevnt:FireServer("equip", {currentType, currentItem})
end)

buyButton.Activated:Connect(function()
	shopevnt:FireServer("buy", {currentType, currentItem})
end)

function refreshDisplay()
	if currentType == "skin" then
		displayItem(currentItem, "knife")
	elseif currentType == "ability" then
		displayItem(currentItem, "ability")
	elseif currentType == "gear" then
			displayItem(currentItem, "gear")
		elseif currentType == "gunskin" then
			displayItem(currentItem, "revolver")
		
	end
end

shopevnt.OnClientEvent:Connect(function(arg1)
	if arg1 == "confirmEquip" then
		script.Parent.useSound:Play()
		refreshStore()
		setupButtons()
		refreshDisplay()
	elseif arg1 == "confirmBuy" then
		script.Parent.confirm:Play()
		refreshStore()
		setupButtons()
		refreshDisplay()
	end
end)

script.Parent.b1.Activated:Connect(function()
	script.Parent.b1.BackgroundColor3 = btnColors.on.Value
	script.Parent.b2.BackgroundColor3 = btnColors.off.Value
	script.Parent.b3.BackgroundColor3 = btnColors.off.Value
	script.Parent.b5.BackgroundColor3 = btnColors.off.Value

	script.Parent.Skins.Visible = false
	script.Parent.Gears.Visible = false
	script.Parent.Abils.Visible = true
	
	currentItem = "Identifier"
	currentType = "ability"
	
	refreshStore()
	setupButtons()
	refreshDisplay()
	
end)

script.Parent.b2.Activated:Connect(function()
	script.Parent.b2.BackgroundColor3 = btnColors.on.Value
	script.Parent.b1.BackgroundColor3 = btnColors.off.Value
	script.Parent.b3.BackgroundColor3 = btnColors.off.Value
	script.Parent.b5.BackgroundColor3 = btnColors.off.Value

	script.Parent.Skins.Visible = false
	script.Parent.Gears.Visible = true
	script.Parent.Abils.Visible = false
	
	currentItem = "None"
	currentType = "gear"
	
	refreshStore()
	setupButtons()
	refreshDisplay()
	
end)

script.Parent.b3.Activated:Connect(function()
	script.Parent.b3.BackgroundColor3 = btnColors.on.Value
	script.Parent.b2.BackgroundColor3 = btnColors.off.Value
	script.Parent.b1.BackgroundColor3 = btnColors.off.Value
	script.Parent.b5.BackgroundColor3 = btnColors.off.Value
	script.Parent.Skins.Visible = true
	script.Parent.Gears.Visible = false
	script.Parent.Abils.Visible = false
	
	currentItem = "Knife"
	currentType = "skin"
	
	refreshStore()
	setupButtons()
	refreshDisplay()
end)
script.Parent.b5.Activated:Connect(function()
	script.Parent.b3.BackgroundColor3 = btnColors.off.Value
	script.Parent.b2.BackgroundColor3 = btnColors.off.Value
	script.Parent.b1.BackgroundColor3 = btnColors.off.Value
	script.Parent.b5.BackgroundColor3 = btnColors.on.Value

	script.Parent.Skins.Visible = false
	script.Parent.RevolverSkins.Visible = true
	script.Parent.Gears.Visible = false
	script.Parent.Abils.Visible = false

	currentItem = "Revolver"
	currentType = "revolverskin"

	refreshStore()
	setupButtons()
	refreshDisplay()
end)

plrCredits.Changed:Connect(function(val)
	script.Parent.Credits.Text = val
	end)
	

here's the full script

W a i t

		for i, v in pairs(script.Parent.RevolverSkins:GetChildren()) do
			if v:IsA("TextButton") then
				v.Activated:connect(function()
					displayItem(v.Name, "revolver")
				end)
			end
		end
	end
	end

Did you mean to put 5 ends? Or just 4? Maybe that’s the reason why? (3 ends for each loop, 1 for ending the function)

let me try changing that and we’ll see

Can you take a screenshot of the error message in the output window? The stack trace normally shows where the error originates, not just the function where it happened.

nope it needed that image