-- Go through each setting value

for _, i in pairs(settingVals) do
	
	-- Make sure not nil
	if i ~= nil then
		
		-- Connect changed event
		i.Changed:connect(function()
			
			-- Set border to be on if this item
			if i.Value == itemName and script.Parent.Parent.Player.Value == plr and script.Parent.ItemType.Value ~= "Emote" and itemName ~= "" then
				
				-- Turn on border
				script.Parent.GreenEdge.Visible = true
				
			else
				
				-- Check if equip nothing as toy button
				if itemName == "" and script.Parent.ItemType.Value == "Toy" then
					
					-- Check if equipped anywhere
					local equipped = false
					for _, o in pairs(settingVals) do
						if o.Value ~= "" then
							equipped = true
							break
						end
					end
					
					-- Only turn on border if nothing equipped
					if equipped then
						script.Parent.GreenEdge.Visible = false
					else
						script.Parent.GreenEdge.Visible = true
					end
					
				else
					
					-- Check if equipped anywhere
					local equipped = false
					for _, o in pairs(settingVals) do
						if o.Value == itemName then
							equipped = true
							break
						end
					end
					
					-- Set border accordingly
					if not equipped then
						script.Parent.GreenEdge.Visible = false
					else
						script.Parent.GreenEdge.Visible = true
					end
					
				end
			end
			
		end)
		
		-- Set up
		if i.Value == itemName and script.Parent.Parent.Player.Value == plr and script.Parent.ItemType.Value ~= "Emote" and (script.Parent.ItemType.Value ~= "Toy" or itemName ~= "") then
			script.Parent.GreenEdge.Visible = true
			plr.PlayerGui.MainGui.Inventory.Preview.Item.Value = actualItem
		end
		
	end
	
end
