Attempt to index nil

So I am making a backpack GUI and I got a problem. I always get the attempt to index nil error. The code does not stop and continues to work normally. I do not know what causes this. Here is the relevant code:

(This is always called when an item is equipped / unequipped) It is checking for nil because when no arguments are given it animates all slots to the unequipped position.

function HandleIconEquip(obj)
	local CurrentSlots = getActiveSlots()
	if obj ~= nil then
		for i = 1, #CurrentSlots do
			if CurrentSlots[i].ToolObject == obj then
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			else
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			end
		end
	else
		for i = 1, #CurrentSlots do
			CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
		end
	end
end

This is used to get all active slots

function getActiveSlots()
	local ActiveSlots = {}
	if Slot1.Name ~= nil and Slot1.ToolObject ~= nil then table.insert(ActiveSlots, Slot1) end
	if Slot2.Name ~= nil and Slot2.ToolObject ~= nil then table.insert(ActiveSlots, Slot2) end
	if Slot3.Name ~= nil and Slot3.ToolObject ~= nil then table.insert(ActiveSlots, Slot3) end
	if Slot4.Name ~= nil and Slot4.ToolObject ~= nil then table.insert(ActiveSlots, Slot4) end
	if Slot5.Name ~= nil and Slot5.ToolObject ~= nil then table.insert(ActiveSlots, Slot5) end
	if Slot6.Name ~= nil and Slot6.ToolObject ~= nil then table.insert(ActiveSlots, Slot6) end
	if Slot7.Name ~= nil and Slot7.ToolObject ~= nil then table.insert(ActiveSlots, Slot7) end
	if Slot8.Name ~= nil and Slot8.ToolObject ~= nil then table.insert(ActiveSlots, Slot8) end
	if Slot9.Name ~= nil and Slot9.ToolObject ~= nil then table.insert(ActiveSlots, Slot9) end
	if Slot0.Name ~= nil and Slot0.ToolObject ~= nil then table.insert(ActiveSlots, Slot0) end
	return ActiveSlots
end

And this is Tool Data

local Slot1 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "1"}
local Slot2 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "2"}
local Slot3 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "3"}
local Slot4 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "4"}
local Slot5 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "5"}
local Slot6 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "6"}
local Slot7 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "7"}
local Slot8 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "8"}
local Slot9 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "9"}
local Slot0 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "0"}

I do not know a solution to this.

What is the full error, and which line is the error on?

(first script)

else
		for i = 1, #CurrentSlots do
			CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
		end
	end

This is the line of the error.

And what is the full error? Attempt to index nil doesn’t tell me everything

Sorry it failed to upload in the original post

Ah thanks. CurrentSlots[i].UiObject is nil. It looks nil in your tool data table too. Do you ever set it to something other than nil?

I do! When the tool (and UIObject) is created. That part of the code works without error Here is the code:

bp.ChildAdded:Connect(function(obj)
	if obj:IsA("Tool") then
		local Slot = FindSmallestAvailableSlot(obj)
		local IsValidTool = IsValidTool(obj)
		if Slot ~= "NoSlot" and IsValidTool == true then
			local TemplateClone = Template:Clone()
			TemplateClone.Parent = Frame
			print("Slot ".. Slot.Value .." is available")
			Slot.UiObject = TemplateClone
			if Slot.Value == "0" then TemplateClone.LayoutOrder = 10 else TemplateClone.LayoutOrder = Slot.Value end
			TemplateClone.Name = obj.Name.. "_Slot".. Slot.Value
			TemplateClone.Object.Frame.Image = obj.TextureId
			TemplateClone.Object.ItemNum.Text = Slot.Value
			TemplateClone.Object.ItemName.Text = obj.Name
			TemplateClone.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.15)
		end
	end
end)

Is it possible for the function with the error to be trying to select a tool that hasn’t yet been set up by this function?

Well all tools are handeled. StarterTools have a seperate function with pretty much the same code (but with a for loop)

Can you run this with the two added prints and share the output please?

function HandleIconEquip(obj)
	local CurrentSlots = getActiveSlots()
    print(CurrentSlots)
	if obj ~= nil then
		for i = 1, #CurrentSlots do
			if CurrentSlots[i].ToolObject == obj then
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			else
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			end
		end
	else
		for i = 1, #CurrentSlots do
        print(i)
			CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
		end
	end
end

Here:
image

Also, here is the structure of the Template:
image

Can you track down why Slot 3 “Flashlight” doesn’t have a UiObject in it?

Oh well I think that will be hard. The code is sloppy I know but I always clean up at the end.I don’t like sharing my full code but here is the entire script:

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Char = Player.Character
local Humanoid = Player.Character:WaitForChild("Humanoid")
local bp = Player.Backpack
local StarterItems = Player.Backpack:GetChildren()

local Template = script.Parent.Template
local Frame = script.Parent.Frame

local ThrowAwayValue = true

--Slots {"TOOL", "NAME"} (Object Value, Name)
local Slot1 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "1"}
local Slot2 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "2"}
local Slot3 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "3"}
local Slot4 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "4"}
local Slot5 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "5"}
local Slot6 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "6"}
local Slot7 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "7"}
local Slot8 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "8"}
local Slot9 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "9"}
local Slot0 = {ToolObject = nil, Name = nil, UiObject = nil, Value = "0"}

function FindSmallestAvailableSlot(ToolObject)
	if Slot1.Name == nil and Slot1.ToolObject == nil then
		Slot1.ToolObject = ToolObject
		Slot1.Name = ToolObject.Name
		return Slot1
	elseif Slot2.Name == nil and Slot2.ToolObject == nil then
		Slot2.ToolObject = ToolObject
		Slot2.Name = ToolObject.Name
		return Slot2
	elseif Slot3.Name == nil and Slot3.ToolObject == nil then
		Slot3.ToolObject = ToolObject
		Slot3.Name = ToolObject.Name
		return Slot3
	elseif Slot4.Name == nil and Slot4.ToolObject == nil then
		Slot4.ToolObject = ToolObject
		Slot4.Name = ToolObject.Name
		return Slot4
	elseif Slot5.Name == nil and Slot5.ToolObject == nil then
		Slot5.ToolObject = ToolObject
		Slot5.Name = ToolObject.Name
		return Slot5
	elseif Slot6.Name == nil and Slot6.ToolObject == nil then
		Slot6.ToolObject = ToolObject
		Slot6.Name = ToolObject.Name
		return Slot6
	elseif Slot7.Name == nil and Slot7.ToolObject == nil then
		Slot7.ToolObject = ToolObject
		Slot7.Name = ToolObject.Name
		return Slot7
	elseif Slot8.Name == nil and Slot8.ToolObject == nil then
		Slot8.ToolObject = ToolObject
		Slot8.Name = ToolObject.Name
		return Slot8
	elseif Slot9.Name == nil and Slot9.ToolObject == nil then
		Slot9.ToolObject = ToolObject
		Slot9.Name = ToolObject.Name
		return Slot9
	elseif Slot0.Name == nil and Slot0.ToolObject == nil then
		Slot0.ToolObject = ToolObject
		Slot0.Name = ToolObject.Name
		return Slot0
	else return "NoSlot"
	end
end

function getActiveSlots()
	local ActiveSlots = {}
	if Slot1.Name ~= nil and Slot1.ToolObject ~= nil then table.insert(ActiveSlots, Slot1) end
	if Slot2.Name ~= nil and Slot2.ToolObject ~= nil then table.insert(ActiveSlots, Slot2) end
	if Slot3.Name ~= nil and Slot3.ToolObject ~= nil then table.insert(ActiveSlots, Slot3) end
	if Slot4.Name ~= nil and Slot4.ToolObject ~= nil then table.insert(ActiveSlots, Slot4) end
	if Slot5.Name ~= nil and Slot5.ToolObject ~= nil then table.insert(ActiveSlots, Slot5) end
	if Slot6.Name ~= nil and Slot6.ToolObject ~= nil then table.insert(ActiveSlots, Slot6) end
	if Slot7.Name ~= nil and Slot7.ToolObject ~= nil then table.insert(ActiveSlots, Slot7) end
	if Slot8.Name ~= nil and Slot8.ToolObject ~= nil then table.insert(ActiveSlots, Slot8) end
	if Slot9.Name ~= nil and Slot9.ToolObject ~= nil then table.insert(ActiveSlots, Slot9) end
	if Slot0.Name ~= nil and Slot0.ToolObject ~= nil then table.insert(ActiveSlots, Slot0) end
	return ActiveSlots
end

function StarterTools()
	for i = 1, #StarterItems do
		if StarterItems[i]:IsA("Tool") then
			local Slot = FindSmallestAvailableSlot(StarterItems[i])
			if Slot ~= "NoSlot" then
				local TemplateClone = Template:Clone()
				TemplateClone.Parent = Frame
				print("Slot ".. Slot.Value .." is available")
				Slot.UiObject = TemplateClone
				if Slot.Value == "0" then TemplateClone.LayoutOrder = 10 else TemplateClone.LayoutOrder = Slot.Value end
				TemplateClone.Name = StarterItems[i].Name.. "_Slot".. Slot.Value
				TemplateClone.Object.Frame.Image = StarterItems[i].TextureId
				TemplateClone.Object.ItemNum.Text = Slot.Value
				TemplateClone.Object.ItemName.Text = StarterItems[i].Name
				TemplateClone.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.15)
			end
		end
	end
end

function handleEquip(tool)
	if tool then
		if tool.Parent ~= Char then
			Humanoid:EquipTool(tool)
		else
			Humanoid:UnequipTools()
		end
	end
end

function IsValidTool(obj)
	if obj ~= Slot1.ToolObject	and obj ~= Slot2.ToolObject and obj ~= Slot3.ToolObject and obj ~= Slot4.ToolObject and obj ~= Slot5.ToolObject and obj ~= Slot6.ToolObject and obj ~= Slot7.ToolObject and obj ~= Slot8.ToolObject	and obj ~= Slot9.ToolObject and obj ~= Slot0.ToolObject then
		return true
	else
		return false
	end
end

bp.ChildAdded:Connect(function(obj)
	if obj:IsA("Tool") then
		local Slot = FindSmallestAvailableSlot(obj)
		local IsValidTool = IsValidTool(obj)
		if Slot ~= "NoSlot" and IsValidTool == true then
			local TemplateClone = Template:Clone()
			TemplateClone.Parent = Frame
			print("Slot ".. Slot.Value .." is available")
			Slot.UiObject = TemplateClone
			if Slot.Value == "0" then TemplateClone.LayoutOrder = 10 else TemplateClone.LayoutOrder = Slot.Value end
			TemplateClone.Name = obj.Name.. "_Slot".. Slot.Value
			TemplateClone.Object.Frame.Image = obj.TextureId
			TemplateClone.Object.ItemNum.Text = Slot.Value
			TemplateClone.Object.ItemName.Text = obj.Name
			TemplateClone.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.15)
		end
	end
end)

bp.ChildRemoved:Connect(function(obj)
	if obj:IsA("Tool") then
		if obj == Slot1.ToolObject and obj.Parent ~= Char then 
			Slot1.ToolObject = nil
			Slot1.Name = nil
			Slot1.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15)
			wait(0.15)
			Slot1.UiObject:Destroy()
			Slot1.UiObject = nil
		end
	end
end)

Char.ChildAdded:Connect(function(obj)
	if obj:IsA("Tool") then
		local Slot = FindSmallestAvailableSlot(obj)
		local IsValidTool = IsValidTool(obj)
		if Slot ~= "NoSlot" and IsValidTool == true then
			local TemplateClone = Template:Clone()
			TemplateClone.Parent = Frame
			print("Slot ".. Slot.Value .." is available")
			Slot.UiObject = TemplateClone
			if Slot.Value == "0" then TemplateClone.LayoutOrder = 10 else TemplateClone.LayoutOrder = Slot.Value end
			TemplateClone.Name = obj.Name.. "_Slot".. Slot.Value
			TemplateClone.Object.Frame.Image = obj.TextureId
			TemplateClone.Object.ItemNum.Text = Slot.Value
			TemplateClone.Object.ItemName.Text = obj.Name
			TemplateClone.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.15)
		end
	end
end)

Char.ChildRemoved:Connect(function(obj)
	if obj:IsA("Tool") and obj.Parent ~= bp then
		if obj == Slot1.ToolObject then Slot1.ToolObject = nil Slot1.Name = nil Slot1.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot1.UiObject:Destroy() Slot1.UiObject = nil
		elseif obj == Slot2.ToolObject then Slot2.ToolObject = nil Slot2.Name = nil Slot2.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot2.UiObject:Destroy() Slot2.UiObject = nil
		elseif obj == Slot3.ToolObject then Slot3.ToolObject = nil Slot3.Name = nil Slot3.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot3.UiObject:Destroy() Slot3.UiObject = nil
		elseif obj == Slot4.ToolObject then Slot4.ToolObject = nil Slot4.Name = nil Slot4.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot4.UiObject:Destroy() Slot4.UiObject = nil
		elseif obj == Slot5.ToolObject then Slot5.ToolObject = nil Slot5.Name = nil Slot5.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot5.UiObject:Destroy() Slot5.UiObject = nil
		elseif obj == Slot6.ToolObject then Slot6.ToolObject = nil Slot6.Name = nil Slot6.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot6.UiObject:Destroy() Slot6.UiObject = nil
		elseif obj == Slot7.ToolObject then Slot7.ToolObject = nil Slot7.Name = nil Slot7.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot7.UiObject:Destroy() Slot7.UiObject = nil
		elseif obj == Slot8.ToolObject then Slot8.ToolObject = nil Slot8.Name = nil Slot8.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot8.UiObject:Destroy() Slot8.UiObject = nil
		elseif obj == Slot9.ToolObject then Slot9.ToolObject = nil Slot9.Name = nil Slot9.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot9.UiObject:Destroy() Slot9.UiObject = nil
		elseif obj == Slot0.ToolObject then Slot0.ToolObject = nil Slot0.Name = nil Slot0.UiObject.Object:TweenPosition(UDim2.new(0, 0, 1.43, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.15) wait(0.15) Slot0.UiObject:Destroy() Slot0.UiObject = nil
		end
	end
end)

function HandleIconEquip(obj)
	local CurrentSlots = getActiveSlots()
	print(CurrentSlots)
	if obj ~= nil then
		for i = 1, #CurrentSlots do
			if CurrentSlots[i].ToolObject == obj then
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			else
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			end
		end
	else
		for i = 1, #CurrentSlots do
			CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
		end
	end
end

function UpdateIconPositions()
	repeat
		local CurrentSlots = getActiveSlots()
		for i = 1, #CurrentSlots do
			if CurrentSlots[i].ToolObject.Parent == Char then
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, -0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			elseif CurrentSlots[i].ToolObject.Parent ~= Char then
				CurrentSlots[i].UiObject.Object:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.05)
			end
		end
	until ThrowAwayValue == false
end

UIS.InputBegan:Connect(function(Key, gameProcessed)
	if Key.KeyCode == Enum.KeyCode.One and Slot1.UiObject ~= nil and not gameProcessed then
		if Slot1.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot1.ToolObject)
			HandleIconEquip(Slot1.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Two and Slot2.UiObject ~= nil and not gameProcessed then
		if Slot2.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot2.ToolObject)
			HandleIconEquip(Slot2.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Three and Slot3.UiObject ~= nil and not gameProcessed then
		if Slot3.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot3.ToolObject)
			HandleIconEquip(Slot3.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Four and Slot4.UiObject ~= nil and not gameProcessed then
		if Slot4.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot4.ToolObject)
			HandleIconEquip(Slot4.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Five and Slot5.UiObject ~= nil and not gameProcessed then
		if Slot5.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot5.ToolObject)
			HandleIconEquip(Slot5.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Six and Slot6.UiObject ~= nil and not gameProcessed then
		if Slot6.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot6.ToolObject)
			HandleIconEquip(Slot6.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Seven and Slot7.UiObject ~= nil and not gameProcessed then
		if Slot7.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot7.ToolObject)
			HandleIconEquip(Slot7.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Eight and Slot8.UiObject ~= nil and not gameProcessed then
		if Slot8.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot8.ToolObject)
			HandleIconEquip(Slot8.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Nine and Slot9.UiObject ~= nil and not gameProcessed then
		if Slot9.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot9.ToolObject)
			HandleIconEquip(Slot9.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	elseif Key.KeyCode == Enum.KeyCode.Zero and Slot0.UiObject ~= nil and not gameProcessed then
		if Slot0.ToolObject.Parent ~= Char then Humanoid:EquipTool(Slot0.ToolObject)
			HandleIconEquip(Slot0.ToolObject)
		else
			Humanoid:UnequipTools()
			HandleIconEquip()
		end
	end
end)


StarterTools()
coroutine.create(UpdateIconPositions)

I think this is the issue. If the object is a tool, FindSmallestAvailableSlot(obj).
FindSmallestAvailableSlot also reserves the slot by setting everything except UiObject. Then, if IsValidTool and Slot ~= NoSlot, proceed to set UiObject and stuff. So I think that perhaps Flashlight is failing IsValidTool.

I would also alter FindSmallestAvailableSlot so that it only returns the slot rather than reserving it by setting the name and the tool. That way if bp.ChildAdded fails any tests, you aren’t left with a partially completed slot.

1 Like

That worked! Thanks for helping.

1 Like